@textlint/markdown-to-ast
Parse Markdown to AST with location info.
Last updated 2 years ago by azu .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ npm install @textlint/markdown-to-ast 
SYNC missed versions from official npm registry.

@textlint/markdown-to-ast

Parse Markdown to AST with location info.

This library is not parser itself, it dependent on wooorm/remark.

Markdown -> remark -> markdown-to-ast -> TxtNodes

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.

The interface are defined in textlint/txtnode.md

This library is a part of textlint/textlint.

If you need to markdown parser, please use wooorm/remark directly.

DEMO

Installation

npm install @textlint/markdown-to-ast

Usage

var parse = require("@textlint/markdown-to-ast").parse;
var markdown = "It's a *text*";
var 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": [
                        0,
                        7
                    ],
                    "raw": "It's a "
                },
                {
                    "type": "Emphasis",
                    "children": [
                        {
                            "type": "Str",
                            "value": "text",
                            "loc": {
                                "start": {
                                    "line": 1,
                                    "column": 8
                                },
                                "end": {
                                    "line": 1,
                                    "column": 12
                                }
                            },
                            "range": [
                                8,
                                12
                            ],
                            "raw": "text"
                        }
                    ],
                    "loc": {
                        "start": {
                            "line": 1,
                            "column": 7
                        },
                        "end": {
                            "line": 1,
                            "column": 13
                        }
                    },
                    "range": [
                        7,
                        13
                    ],
                    "raw": "*text*"
                }
            ],
            "loc": {
                "start": {
                    "line": 1,
                    "column": 0
                },
                "end": {
                    "line": 1,
                    "column": 13
                }
            },
            "range": [
                0,
                13
            ],
            "raw": "It's a *text*"
        }
    ],
    "loc": {
        "start": {
            "line": 1,
            "column": 0
        },
        "end": {
            "line": 1,
            "column": 13
        }
    },
    "range": [
        0,
        13
    ],
    "raw": "It's a *text*"
}
*/

If you want to know real use-case, please see textlint/textlint.

Tests

npm test

Create fixtures

See tools/ directory.

Contributing

  1. Fork it!
  2. Create your feature branch: git checkout -b my-new-feature
  3. Commit your changes: git commit -am 'Add some feature'
  4. Push to the branch: git push origin my-new-feature
  5. Submit a pull request :D

License

MIT

Current Tags

  • 12.0.0-beta.3                                ...           beta (3 years ago)
  • 6.1.0-alpha.0f2fd6f9                                ...           canary (6 years ago)
  • 14.2.0                                ...           latest (3 months ago)
  • 13.4.2-next.0                                ...           next (9 months ago)

74 Versions

  • 14.2.0                                ...           3 months ago
  • 14.1.0                                ...           3 months ago
  • 14.0.5                                ...           3 months ago
  • 14.0.4                                ...           8 months ago
  • 14.0.3                                ...           9 months ago
  • 14.0.2                                ...           9 months ago
  • 14.0.1                                ...           9 months ago
  • 14.0.0                                ...           9 months ago
  • 13.4.2-next.0                                ...           9 months ago
  • 13.4.1                                ...           a year ago
  • 13.4.0                                ...           a year ago
  • 13.3.3                                ...           a year ago
  • 13.3.2                                ...           2 years ago
  • 13.3.1                                ...           2 years ago
  • 13.3.0                                ...           2 years ago
  • 13.2.0                                ...           2 years ago
  • 13.1.4                                ...           2 years ago
  • 13.1.3                                ...           2 years ago
  • 13.1.2                                ...           2 years ago
  • 13.1.1                                ...           2 years ago
  • 13.1.0                                ...           2 years ago
  • 13.0.5                                ...           2 years ago
  • 13.0.4                                ...           2 years ago
  • 13.0.3                                ...           2 years ago
  • 13.0.2                                ...           2 years ago
  • 13.0.1                                ...           2 years ago
  • 13.0.0                                ...           2 years ago
  • 12.6.1                                ...           2 years ago
  • 12.6.0                                ...           2 years ago
  • 12.5.2                                ...           2 years ago
  • 12.5.0                                ...           2 years ago
  • 12.3.0                                ...           2 years ago
  • 12.2.3                                ...           2 years ago
  • 12.2.2                                ...           2 years ago
  • 12.2.1                                ...           2 years ago
  • 12.2.0                                ...           2 years ago
  • 12.1.1                                ...           3 years ago
  • 12.1.0                                ...           3 years ago
  • 12.0.2                                ...           3 years ago
  • 12.0.0                                ...           3 years ago
  • 12.0.0-beta.3                                ...           3 years ago
  • 12.0.0-beta.2                                ...           3 years ago
  • 12.0.0-beta.1                                ...           3 years ago
  • 12.0.0-beta.0                                ...           3 years ago
  • 6.3.5                                ...           4 years ago
  • 6.3.4                                ...           4 years ago
  • 6.3.3                                ...           4 years ago
  • 6.3.2                                ...           4 years ago
  • 6.3.1                                ...           4 years ago
  • 6.3.0                                ...           4 years ago
  • 6.2.6                                ...           4 years ago
  • 6.2.5                                ...           4 years ago
  • 6.2.4                                ...           4 years ago
  • 6.2.3                                ...           4 years ago
  • 6.2.2                                ...           4 years ago
  • 6.2.1                                ...           4 years ago
  • 6.2.0                                ...           4 years ago
  • 6.1.7                                ...           5 years ago
  • 6.1.6                                ...           5 years ago
  • 6.1.5                                ...           5 years ago
  • 6.1.4                                ...           5 years ago
  • 6.1.3                                ...           6 years ago
  • 6.1.2                                ...           6 years ago
  • 6.1.1                                ...           6 years ago
  • 6.1.0                                ...           6 years ago
  • 6.0.9                                ...           6 years ago
  • 6.1.0-alpha.0f2fd6f9                                ...           6 years ago
  • 6.1.0-alpha.bbfc8f6d                                ...           6 years ago
  • 6.0.8                                ...           7 years ago
  • 6.0.7                                ...           7 years ago
  • 6.0.6                                ...           7 years ago
  • 6.0.5                                ...           7 years ago
  • 6.0.4                                ...           7 years ago
  • 6.0.3                                ...           7 years ago
Maintainers (2)
Downloads
Total 1
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 0
Last Month 0
Dependencies (8)
Dev Dependencies (13)
Dependents (1)

© 2010 - cnpmjs.org x YWFE | Home | YWFE