markdown library

Parses text in a Markdown-like format building an AST tree that can then be rendered to HTML.

If you are only interested in rendering Markdown to HTML please refer to the README which explains the use of markdownToHtml.

The main entrypoint to the library is the Document which encapsulates the parsing process converting a Markdown text into a tree of Node (List<Node>).

The two main parsing mechanics used are:

  • Blocks, representing top-level elements implemented via BlockSyntax subclasses, such as headers, paragraphs, blockquotes, and code blocks.
  • Inlines, representing chunks of text within a block with special meaning, implemented via InlineSyntax subclasses, such as links, emphasis, and inlined code.

Looking closely at Document.new a few other concepts merit a mention:

  • ExtensionSet that provide configurations for common Markdown flavors
  • Resolver which aid in resolving links and images

If you are looking at extending the library to support custom formatting what you might want is to:

Classes

AlertBlockSyntax
Parses GitHub Alerts blocks.
AutolinkExtensionSyntax
Matches autolinks like http://foo.com and foo@bar.com.
AutolinkSyntax
Matches autolinks like <http://foo.com>.
BlockParser
Maintains the internal state needed to parse a series of lines into blocks of Markdown suitable for further inline parsing.
BlockquoteSyntax
Parses email-style blockquotes: > quote.
BlockSyntax
CodeBlockSyntax
Parses preformatted code blocks that are indented four spaces.
CodeSyntax
Matches backtick-enclosed inline code blocks.
ColorSwatchSyntax
Matches code blocks containing a subset of CSS color syntax.
DecodeHtmlSyntax
Decodes numeric character references, for example decode &#35; to #.
Delimiter
A delimiter indicating the possible "open" or possible "close" of a tag for a DelimiterSyntax.
DelimiterRun
An implementation of Delimiter which uses concepts of "left-flanking" and "right-flanking" to determine the values of canOpen and canClose.
DelimiterSyntax
Matches syntax that has a pair of tags and becomes an element, like * for <em>. Allows nested tags.
DelimiterTag
Document
Maintains the context needed to parse a Markdown document.
DummyBlockSyntax
Walks the parser forward through the lines does not match any BlockSyntax.
Element
A named tag that can contain other nodes.
EmailAutolinkSyntax
Matches autolinks like <foo@bar.example.com>.
EmojiSyntax
Matches GitHub Markdown emoji syntax like :smile:.
EmphasisSyntax
EmptyBlockSyntax
EscapeHtmlSyntax
Encodes ("), (<), (>) and (&).
EscapeSyntax
Escape ASCII punctuation preceded by a backslash.
ExtensionSet
ExtensionSets provide a simple grouping mechanism for common Markdown flavors.
FencedBlockquoteSyntax
Parses lines fenced by >>> to blockquotes
FencedCodeBlockSyntax
Parses preformatted code blocks between two ~~~ or ``` sequences.
FootnoteDefSyntax
The spec of GFM about footnotes is missing. For online source code of cmark-gfm, see master@c32ef78. A Rust implementation is also available. Footnote definition could contain multiple line-children and children could be separated by one empty line. Its first child-line would be the remaining part of the first line after taking definition leading, combining with other child lines parsed by parseChildLines, is fed into BlockParser.
HeaderSyntax
Parses atx-style headers: ## Header ##.
HeaderWithIdSyntax
Parses atx-style headers, and adds generated IDs to the generated elements.
HorizontalRuleSyntax
Parses horizontal rules like ---, _ _ _, * * *, etc.
HtmlBlockSyntax
Parse HTML blocks.
HtmlRenderer
Translates a parsed AST to HTML.
ImageSyntax
Matches images like ![alternate text](url "optional title") and ![alternate text][label].
InlineHtmlSyntax
Leave inline HTML tags alone, from CommonMark 0.30.
InlineParser
Maintains the internal state needed to parse inline span elements in Markdown.
InlineSyntax
Represents one kind of Markdown tag that can be parsed.
Line
A Line is a sequence of zero or more characters other than line feed (U+000A) or carriage return (U+000D), followed by a line ending or by the end of file.
LineBreakSyntax
Represents a hard line break.
LinkContext
A helper class holds params of link context. Footnote creation needs other info in _tryCreateReferenceLink.
LinkReference
A link reference definition.
LinkSyntax
Matches links like [blah][label] and [blah](url).
ListItem
ListSyntax
Base class for both ordered and unordered lists.
Node
Base class for any AST item.
NodeVisitor
Visitor pattern for the AST.
OrderedListSyntax
Parses ordered lists.
OrderedListWithCheckboxSyntax
Parses ordered lists with checkboxes.
ParagraphSyntax
Parses paragraphs of regular text.
SetextHeaderSyntax
Parses setext-style headers.
SetextHeaderWithIdSyntax
Parses setext-style headers, and adds generated IDs to the generated elements.
SimpleDelimiter
A simple delimiter implements the Delimiter interface with basic fields, and does not have the concept of "left-flanking" or "right-flanking".
SoftLineBreakSyntax
Removes the single space before the line ending.
StrikethroughSyntax
Matches strikethrough syntax according to the GFM spec.
TableSyntax
Parses tables.
Text
A plain text element.
TextSyntax
Matches stuff that should just be passed through as straight text.
UnorderedListSyntax
Parses unordered lists.
UnorderedListWithCheckboxSyntax
Parses unordered lists with checkboxes.
UnparsedContent
Inline content that has not been parsed into inline nodes (strong, links, etc).

Constants

emojis → const Map<String, String>
version → const String

Functions

markdownToHtml(String markdown, {Iterable<BlockSyntax> blockSyntaxes = const [], Iterable<InlineSyntax> inlineSyntaxes = const [], ExtensionSet? extensionSet, Resolver? linkResolver, Resolver? imageLinkResolver, bool inlineOnly = false, bool encodeHtml = true, bool enableTagfilter = false, bool withDefaultBlockSyntaxes = true, bool withDefaultInlineSyntaxes = true}) String
Converts the given string of Markdown to HTML.
renderToHtml(List<Node> nodes, {bool enableTagfilter = false}) String
Renders nodes to HTML.

Typedefs

Resolver = Node? Function(String name, [String? title])