@yozora/parser
A markdown parser with rich built-in tokenizers.
- See github flavor markdown spec for details.
- See GFM Live Examples for an intuitive impression.
Install
- npm
- Yarn
- pnpm
npm install --save @yozora/parser
yarn add @yozora/parser
pnpm add @yozora/parser
Usage
-
Basic
import YozoraParser from '@yozora/parser'
const parser = new YozoraParser()
// 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 YozoraParser from '@yozora/parser'
const parser = new YozoraParser()
/**
* 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 Node produced presetDefinitions
Array<Omit<Definition, 'type'>
false
Preset definitions presetFootnoteDefinitions
Array<Omit<FootnoteDefinition, 'type'>
false
Preset footnote definition
Overview
-
Built-in tokenizers
-
All tokenizers for processing tokens defined Github Flavor Markdown:
-
Additional tokenizers
Tokenizer Description @yozora/tokenizer-admonition Resolve admonitions @yozora/tokenizer-footnote Resolve footnotes @yozora/tokenizer-footnote-definition Resolve footnote definitions @yozora/tokenizer-footnote-reference Resolve footnote references @yozora/tokenizer-inline-math Resolve inline formulas @yozora/tokenizer-math Resolve block formulas
-
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.
Hard line breaks
See @yozora/tokenizer-break for details.