markdown-to-ast

Parse Markdown to AST with location info.

See https://github.com/textlint/textlint/issues/455
Last updated 10 years ago by azu .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ npm install markdown-to-ast 
SYNC missed versions from official npm registry.

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

screenshot

Online Parsing Demo provide markdown to AST on-the-fly.

Installation

npm install markdown-to-ast

Usage

var parse = require("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

  • 4.1.0-alpha.6a53d00c                                ...           canary (7 years ago)
  • 6.0.3                                ...           latest (7 years ago)
  • 6.0.0-next.0                                ...           next (7 years ago)

29 Versions

  • 6.0.3 [deprecated]           ...           7 years ago
  • 6.0.2 [deprecated]           ...           7 years ago
  • 6.0.1 [deprecated]           ...           7 years ago
  • 6.0.0 [deprecated]           ...           7 years ago
  • 6.0.0-next.0                                ...           7 years ago
  • 5.0.0 [deprecated]           ...           7 years ago
  • 5.0.0-beta.0                                ...           7 years ago
  • 4.1.0-alpha.6a53d00c                                ...           7 years ago
  • 4.0.0 [deprecated]           ...           8 years ago
  • 3.4.0 [deprecated]           ...           9 years ago
  • 3.2.3 [deprecated]           ...           9 years ago
  • 3.2.1 [deprecated]           ...           9 years ago
  • 3.2.0 [deprecated]           ...           9 years ago
  • 3.1.1 [deprecated]           ...           9 years ago
  • 3.0.7 [deprecated]           ...           9 years ago
  • 3.0.5 [deprecated]           ...           10 years ago
  • 3.0.3 [deprecated]           ...           10 years ago
  • 3.0.2 [deprecated]           ...           10 years ago
  • 2.2.1 [deprecated]           ...           10 years ago
  • 3.0.1 [deprecated]           ...           10 years ago
  • 3.0.0 [deprecated]           ...           10 years ago
  • 2.2.0 [deprecated]           ...           10 years ago
  • 2.1.0 [deprecated]           ...           10 years ago
  • 2.0.0 [deprecated]           ...           10 years ago
  • 1.2.0 [deprecated]           ...           10 years ago
  • 1.1.1 [deprecated]           ...           10 years ago
  • 1.1.0 [deprecated]           ...           10 years ago
  • 1.0.2 [deprecated]           ...           10 years ago
  • 1.0.1 [deprecated]           ...           10 years ago
Maintainers (1)
Downloads
Total 0
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 0
Last Month 0
Dependencies (5)
Dev Dependencies (7)
Dependents (1)

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