package
Parse Markdown to AST with location info.
npm install @textlint/markdown-to-astGitHub-flavored package documentation.
Across all versions.
Download trend unavailable.
Runtime metadata.
Estimated unpacked size across 2 packages.
519.6 kB
Includes dependencies.
Parse Markdown to AST with location info.
This library is a CommonMark + GFM parser that produces TxtNodes directly.
It has no third-party dependencies.
Markdown -> markdown-to-ast ->
TxtNodes
Supported syntax:
[^1] and [^1]: note) and inline notes(^[note])---), TOML(+++), JSON(;;; or {)The parser follows CommonMark for everything CommonMark defines, and GFM for the extensions GFM defines. The node of each syntax, its properties, and its range are defined in the Markdown parsing requirements.
Front matter and footnotes are not part of CommonMark/GFM, so their nodes are extension nodes with lowercase type names: yaml, toml, json, footnoteReference, footnoteDefinition, and footnote.
The AST consists of TxtNodes.
A TxtNode of the AST has following properties:
loc - Nodes have line and column-based location info.range - Nodes have an index-based location range (array).raw - Node have a raw text.value - Node have a value of text.raw, range, and loc of a node always describe the same span of the text.
The interface are defined in textlint/txtnode.md
This library is a part of textlint/textlint.
If you need a general-purpose Markdown parser (mdast, HTML output, plugins), please use remark directly.
The parser is written with data-oriented design for performance. See the Markdown parsing design for details.
raw and value are sliced from the source text when the AST is emittedTxtNode objects are created only once at the end. There is no intermediate AST such as mdastparse() callsThe parser does not overflow the call stack for deeply nested inputs.
BlockQuote, List, ListItem, footnoteDefinition) and 100 for inline nodes (Emphasis, Strong, Delete, Link, LinkReference, footnote)npm install @textlint/markdown-to-astimport { parse } from "@textlint/markdown-to-ast";
const markdown = "It's a *text*";
const AST = parse(markdown);
/*
{
"type": "Document",
"children": [
{
"type": "Paragraph",
"children": [
{
"type": "Str",
"value": "It's a ",
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 1,
"column": 7
}
},
"range": [
If you want to know real use-case, please see textlint/textlint.
parse(text, options) takes these options. All of them are false by default.
cjkFriendlyEmphasis: Recognize emphasis, strong emphasis, and strikethrough next to CJK punctuation, as the CommonMark CJK-friendly Amendments define. **強調。**この文 becomes Strong and Str.const AST = parse("**強調。**この文", { cjkFriendlyEmphasis: true });npm testSee tools/ directory.
git checkout -b my-new-featuregit commit -am 'Add some feature'git push origin my-new-featureMIT
textlint-user
azuciao+textlint@gmail.com