Détail du package

markdown-to-ast

textlint39kMITobsolète6.0.3

See https://github.com/textlint/textlint/issues/455

Parse Markdown to AST with location info.

readme

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

changelog

Change Log

All notable changes to this project will be documented in this file. See Conventional Commits for commit guidelines.

6.0.3 (2018-01-12)

Note: Version bump only for package markdown-to-ast

6.0.2 (2017-12-31)

Note: Version bump only for package markdown-to-ast

6.0.1 (2017-12-25)

Note: Version bump only for package markdown-to-ast

6.0.0 (2017-12-18)

Note: Version bump only for package markdown-to-ast

6.0.0-next.0 (2017-12-15)

Note: Version bump only for package markdown-to-ast

4.0.0 (2017-05-06)

Bug Fixes

  • example: fix path (3047d10)
  • example: update (a8e4941)
  • npm: move debug module to dependency (eef12f0)
  • npm: move dev to dependecies (8e7cd32)
  • parse: use thematicBreak as a map key (b9fe7d1)
  • readme: fix outdated link (5697807), closes #9
  • remark: fix usage of remark (8702d24)
  • test: fix test on Windows (956c6d1)
  • test: rename test case (821c650)
  • test: update to mdast latest (9eee76d)
  • travis: fix path to shell-script (13c0174)

Features

  • ast: enable SetextHeader test (f980d41)
  • ast: implement Break node (fb41948)
  • ast: implement HorizontalRule node (a01084c)
  • ast: implement Html node (3b94068)
  • ast: implement some node (f6bbd54)
  • ast: re-implement Code (832cbd6)
  • ast: re-implement CodeBlock (902a6c8)
  • ast: re-implement Emphasis node (6faf2f3)
  • ast: re-implement Strong node (307c037)
  • demo: add title (174ac1b)
  • markdown: update remark to 4.x (f44a326)
  • markdown-to-ast: update remark@7 (#278) (197d5d4)
  • parser: add loc object to Document type node (dcc7e2b)
  • parser: add workaround for Header (e79ab46)
  • parser: correct range of CodeBlock (583b1d7)
  • parser: correct raw property of BlockQuote (a38bdf9)
  • parser: correct raw property of Code (ef4535f)
  • parser: correct raw property of Emph (6da8e88)
  • parser: correct raw property of Image (27f46d0)
  • parser: correct raw property of List type (59f1723)
  • parser: correct raw property of Strong (2265122)
  • parser: correct raw property of LiteItem (8414d50)
  • parser: correct start_column of each nodes. (408e97b)
  • parser: implement Header of raw (740d11a)
  • parser: remove un-used properties (f72fde8)
  • parser: update to commonmark 0.15 (f31eaa3)
  • travis: add npm run build (69eaa48)
  • travis: add travis badge (7121865)
  • travis: auto deploy to gh-page (a686595)

BREAKING CHANGES

  • markdown-to-ast: some parse result is changed.

It is correct, but we think that is a breacking change. This change have possibilities that the user update patch-version textlint and fail test.

close https://github.com/textlint/markdown-to-ast/issues/14