Based on commonmark.js
FlavorMark is a Markdown parser, made in TypeScript, with emphasis placed on modularizing element parsing logic, making it easy(-ish) to add/remove syntax for your favorite Markdown flavors.
There are a lot of classes with the word Parser in them.
-
ParserThe main parser, parses block elements. Then, parses inline content.
-
BlockParserEach block element will generally be parsed by one
BlockParser. -
InlineContentParserParses inline content, using
InlineParser. -
InlineParserEach inline element will generally be parsed by one
InlineParser. -
DelimitedInlineParserThis parser makes it easier to parse inline elements that behave like emphasis elements.
-
DelimitedInlineSubParserIf using
DelimitedInlineParser, each sub-parser will parse one emphasis-like element. (Emphasis, smart quotes, superscript, strikethrough, etc.)
- Instantiate all
BlockParserclasses and add them to aBlockParserCollection. - Instantiate all
InlineParserclasses and add them to an array. - Instantiate an
InlineContentParserand pass it the array ofInlineParser. - Instantiate a
Parserand pass it theBlockParserCollection, andInlineContentParser. - Call
Parser.parse(str).
See the tests in src/test for more examples.
Each Node constructor is used to uniquely identify BlockParser, and HtmlSubRenderer
instances.
When trying to parse a block, instanceof checks are used to find the BlockParser
associated with a Node. The first matching BlockParser in the array is used.
For this reason, each unique block type should have its own Node sub-class.
See LICENSE file (copy-pasted from commonmark.js).
Also, since this is just a glorified port of commonmark.js,
I guess the BSD-license carries over. I have no idea how this works. I don't really
care, personally. I just don't want to step on anyone's toes.