@yozora/parser-gfm
A markdown parser with built-in tokenizers to fully support GFM (without GFM extensions).
- See github flavor markdown spec for details.
- See GFM Live Examples for an intuitive impression.
Installโ
- npm
- Yarn
- pnpm
npm install --save @yozora/parser-gfm
yarn add @yozora/parser-gfm
pnpm add @yozora/parser-gfm
Usageโ
-
Basic
import GfmParser from '@yozora/parser-gfm'
const parser = new GfmParser()
// parse markdown source content.
parser.parse('source markdown content')
// parse markdown source content with custom options.
parser.parse(
'source markdown content', // markdown source contents, `string|Iterable<string>`
{}, // ParseOptions, optional.
)
// parse multiple markdown source content pieces.
parser.parse(['source', 'contents']) -
Use withing generator:
import GfmParser from '@yozora/parser-gfm'
const parser = new GfmParser()
/**
* String stream is supported through the iterator API.
*/
function* source () {
yield 'hello',
yield 'world',
}
parser.parse(source())
Optionsโ
-
Constructor Options
Name Type Required Description blockFallbackTokenizer
BlockFallbackTokenizer
false
Fallback tokenizer on processing block structure phase inlineFallbackTokenizer
InlineFallbackTokenizer
false
Fallback tokenizer on processing inline structure phase defaultParseOptions
ParseOptions
false
Default options for parse()
-
ParseOptions
Name Type Required Description shouldReservePosition
boolean
false
Whether it is necessary to reserve the position in the YastNode produced presetDefinitions
Array<Omit<Definition, 'type'>
false
Preset definitions presetFootnoteDefinitions
Array<Omit<FootnoteDefinition, 'type'>
false
Preset footnote definition
Overviewโ
-
Built-in tokenizers
Live Examplesโ
Thematic breakโ
See @yozora/tokenizer-thematic-break for details.
ATX headingsโ
See @yozora/tokenizer-heading for details.
Setext headingsโ
See @yozora/tokenizer-setext-heading for details.
Indented code blocksโ
See @yozora/tokenizer-indented-code for details.
Fenced code blocksโ
See @yozora/tokenizer-fenced-code for details.
HTML blocksโ
See @yozora/tokenizer-html-block for details.
Link reference definitionsโ
See @yozora/tokenizer-definition for details.
Paragraphsโ
See @yozora/tokenizer-paragraph for details.
Tables (extension)โ
See @yozora/tokenizer-table for details.
Block quotesโ
See @yozora/tokenizer-blockquote for details.
List itemsโ
See @yozora/tokenizer-list for details.
Task list items (extension)โ
See @yozora/tokenizer-list for details.
Listsโ
See @yozora/tokenizer-list for details.
Code spansโ
See @yozora/tokenizer-inline-code for details.
Emphasis and strong emphasisโ
See @yozora/tokenizer-emphasis for details.
Strikethrough (extension)โ
See @yozora/tokenizer-delete for details.
Linksโ
See @yozora/tokenizer-link for details.
Reference linksโ
See @yozora/tokenizer-link-reference for details.
Imagesโ
See @yozora/tokenizer-image for details.
Reference imagesโ
See @yozora/tokenizer-image-reference for details.
Autolinksโ
See @yozora/tokenizer-autolink for details.
Autolinks (extension)โ
See @yozora/tokenizer-autolink-extension for details.
Raw HTMLโ
See @yozora/tokenizer-html-inline for details.