mawy library
Mawy — a Markdown viewer that also does the parsing.
The document becomes widgets rather than a string of HTML, which is what makes the safe default free: there is no markup on the path from Markdown to the screen, so there is nothing to escape and nowhere for an injection to arrive.
The parser is this package's own, and it is the React package's own parser
in Dart — the same file names, the same functions, the same rules. A
document that means one thing in a browser means the same thing here, and
tool/parity.dart is what keeps that true rather than hoped for.
Nothing here imports package:flutter/material.dart or
package:flutter/cupertino.dart. Every widget is built on
package:flutter/widgets.dart alone, which is what lets a document sit
inside a Material app, a Cupertino app or a bare WidgetsApp without
dragging a second design system in behind it.
import 'package:mawy/mawy.dart';
MawyViewer(value: '# Hello\n\nSome **Markdown**.')
Classes
- EditState
- A document and where the caret is in it.
- MawyCodeGroup
- The tabs a MawyDirectiveBuilder draws. See the library's own comment.
- MawyCodeToken
- One run of a code block, and what it is.
- MawyDirective
- A directive, on its way to the builder that knows what it means.
- MawyEditor
- A Markdown editor: the source, a preview, and a switch between them.
- MawyEditorHandle
- What an application can do to an editor from outside it.
- MawyHighlighter
- Something that can colour a code block.
- MawyImage
- A picture the document asked for.
- MawyMatch
- Where one match sits in the document.
- MawyMotion
- How long anything takes to move, and how it moves.
- MawyParseOptions
- How the Markdown itself is read.
- MawyRadius
- The corner radii, which are three sizes and not a scale.
- MawyReplaced
- A document as a replacement left it, and where the caret went.
- MawyReplacedAll
- A document as "replace all" left it, and how many it replaced.
- MawyStrings
- Every word the interface says, by name.
- MawyTokens
- One palette: every colour a document and its interface are drawn in.
- MawyTypography
- How the document is set.
- MawyViewer
- A Markdown document, drawn.
- MawyViewerAnchors
- The blocks of one viewer's document, and where they are.
- MdBlock
- A block: something that stands on its own down the page.
- MdBlockquote
- A quotation, and the five GitHub alerts that are written as one.
- MdBreak
- A hard line break.
- MdCode
- A fenced or indented code block.
- MdContainerDirective
- A construct the parser reads and does not understand.
- MdDefinition
- A link reference definition, keyed by its normalised label.
- MdDefinitionDescription
- What a term means. Blocks, because a definition can be a whole paragraph.
- MdDefinitionList
- A term and what it means, which Markdown proper has no way of writing.
- MdDefinitionTerm
- The word being defined. One line, and inline content like a heading's.
- MdDelete
-
~~struck through~~. - MdDocument
- A parsed document: the tree, its outline, and the footnotes under it.
- MdEmphasis
-
*emphasis*. - MdFootnoteDefinition
- A footnote, where it was written.
- MdFootnoteReference
-
A
[^label]in a sentence, pointing at a footnote written elsewhere. - MdHeading
- A heading, written with hashes or with an underline.
- MdHtmlBlock
- A run of raw HTML written as a block.
- MdImage
- An image.
- MdInline
- A run of text inside a block.
- MdInlineCode
-
`code`. - MdInlineHtml
- A run of raw HTML written inside a sentence, shown as the text it is.
- MdLeafDirective
-
::name[label]{attrs}on a line of its own. - MdLink
- A link.
- MdList
- A bullet or ordered list.
- MdListItem
- One item of a list.
- MdNode
- Anything in the tree: a block, an inline, or one of the pieces in between.
- MdOutlineEntry
- One heading, as the outline lists it.
- MdParagraph
- A paragraph.
- MdRange
-
Where a node came from: the half-open range of the source it was read out
of, in the offsets of the string handed to
parseMarkdown. - MdRoot
- The document itself, and everything in it.
- MdStrong
-
**strong**. - MdTable
- A GitHub table.
- MdTableCell
- One cell of a table row.
- MdTableRow
- One row of a table.
- MdText
- A run of plain text.
- MdTextDirective
-
:name[label]{attrs}inside a sentence. See MdContainerDirective. - MdThematicBreak
- A horizontal rule.
Enums
- MawyCodeTokenKind
- What a run of a code block is, as far as a highlighter is willing to say.
- MawyColorScheme
- Which palette to draw in.
- MawyCommand
- One thing the toolbar can do.
- MawyDirectiveKind
- Which of the three shapes a directive was written in.
- MawyEditorMode
- Which surface the editor is showing.
- MawyEditorStatusItem
- What the editor counts along its bottom edge.
- MawyEditorToolbarItem
- One control on the editor's toolbar.
- MawyFontFamily
- Which typeface the document is set in.
- MawyFrame
- Whether the surface has a frame around it, or floats in the page.
- MawyImagePolicy
- How a picture the document asks for is drawn.
- MawyLinkPolicy
- How a link the document wrote is drawn.
- MawyLocale
- The language the viewer's own interface is written in.
- MawyMeasure
- How wide the text is allowed to run.
- MawyToolbarPlacement
- Which end of the surface the toolbar is at.
- MawyUrlKind
- Which of the two a URL was written as.
- MawyViewerToolbarItem
- One control on the viewer's toolbar.
- MdAlertKind
- The five kinds of GitHub alert a quotation can open with.
- MdAlign
-
Where a table column's content sits.
nullis "the column said nothing".
Extensions
- MawyMeasureWidth on MawyMeasure
- The widest a column of text may be, in logical pixels.
Constants
-
kMawyEditorModes
→ const List<
MawyEditorMode> - The surfaces an editor offers unless it is told otherwise.
-
kMawyEditorStatus
→ const List<
MawyEditorStatusItem> - The counts an editor shows unless it is told otherwise.
-
kMawyEditorToolbar
→ const List<
MawyEditorToolbarItem> - The toolbar an editor draws unless it is told otherwise.
-
kMawyViewerToolbar
→ const List<
MawyViewerToolbarItem> - Everything the toolbar offers, in the order it draws them.
- mawyHighlighter → const MawyHighlighter
- The highlighter itself.
Properties
-
kMawyHighlightLanguages
→ List<
String> -
The names this highlighter answers to, for a documentation page to list.
no setter
Functions
-
commandActive(
MawyCommand command, EditState state) → bool - Whether the selection is already what the command would make it.
-
continueList(
EditState state, {bool definitionLists = true}) → EditState? - What Enter should do, when the line it was pressed on is a list item.
-
findMatches(
String value, String query, bool matchCase) → List< MawyMatch> - Every match, in the order they appear.
-
indent(
EditState state, {required bool out}) → EditState -
TabandShift+Tab, over whatever the selection touches. -
matchFrom(
List< MawyMatch> matches, int caret, {required bool forwards}) → int - Which match to go to from where the caret is.
-
parseMarkdown(
String source, [MawyParseOptions options = const MawyParseOptions()]) → MdDocument -
Reads
sourceas Markdown. -
replaceAll(
String value, String query, String replacement, bool matchCase) → MawyReplacedAll - Every match, replaced in one pass.
-
replaceMatch(
String value, MawyMatch match, String replacement) → MawyReplaced - One match, replaced.
-
runCommand(
MawyCommand command, EditState state) → EditState -
What
commandmakes ofstate. -
slugify(
String text) → String - A heading's anchor, in the spelling GitHub uses.
Typedefs
- MawyDirectiveBuilder = Widget Function(BuildContext context, MawyDirective directive)
- What draws one directive.
- MawyImageBuilder = Widget Function(BuildContext context, MawyImage image)
- What draws a picture the document points at.
- MawyTokensBuilder = MawyTokens Function(Brightness brightness)
- A palette per brightness, for an application that wants its own.
- MawyUrlResolver = String Function(String url, MawyUrlKind kind)
- Where a relative URL points.