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>).

Two main parsing mechanics are used:

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

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 may want is to:

Classes

AutolinkExtensionSyntax
Matches autolinks like http://foo.com.
AutolinkSyntax
Matches autolinks like <http://foo.com>.
BlockHtmlSyntax
Parses inline HTML at the block level. This differs from other Markdown implementations in several ways:
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
BlockTagBlockHtmlSyntax
CodeBlockSyntax
Parses preformatted code blocks that are indented four spaces.
CodeSyntax
Matches backtick-enclosed inline code blocks.
Delimiter
A delimiter indicating the possible "open" or possible "close" of a tag for a TagSyntax.
DelimiterRun
An implementation of Delimiter which uses concepts of "left-flanking" and "right-flanking" to determine the values of canOpen and canClose.
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:.
EmptyBlockSyntax
EscapeSyntax
Escape 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.
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.
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.28.
InlineParser
Maintains the internal state needed to parse inline span elements in Markdown.
InlineSyntax
Represents one kind of Markdown tag that can be parsed.
LineBreakSyntax
Represents a hard line break.
LinkReference
A link reference definition.
LinkSyntax
Matches links like [blah][label] and [blah](url).
ListItem
ListSyntax
Base class for both ordered and unordered lists.
LongBlockHtmlSyntax
A BlockHtmlSyntax that has a specific endPattern.
Node
Base class for any AST item.
NodeVisitor
Visitor pattern for the AST.
OrderedListSyntax
Parses ordered lists.
OtherTagBlockHtmlSyntax
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".
StrikethroughSyntax
Matches strikethrough syntax according to the GFM spec.
TableSyntax
Parses tables.
TagSyntax
Matches syntax that has a pair of tags and becomes an element, like * for <em>. Allows nested tags.
Text
A plain text element.
TextSyntax
Matches stuff that should just be passed through as straight text.
UnorderedListSyntax
Parses unordered lists.
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 withDefaultBlockSyntaxes = true, bool withDefaultInlineSyntaxes = true}) String
Converts the given string of Markdown to HTML.
renderToHtml(List<Node> nodes) String
Renders nodes to HTML.

Typedefs

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