14.0.4 • Published 2 months ago

@textlint/text-to-ast v14.0.4

Weekly downloads
13,646
License
MIT
Repository
github
Last release
2 months ago

@textlint/text-to-ast

Parse plain text to AST with location info.

This library is a part of textlint/textlint.

Markdown version: @textlint/markdown-to-ast

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.

Installation

npm install @textlint/text-to-ast

DEMO

Usage

var parse = require("@textlint/text-to-ast").parse;
var text = "This is a text\nParse text to AST";
var AST = parse(text);
console.log(JSON.stringify(AST, null ,4))
/*
{
    "type": "Document",
    "range": [
        0,
        32
    ],
    "loc": {
        "start": {
            "line": 1,
            "column": 0
        },
        "end": {
            "line": 2,
            "column": 17
        }
    },
    "children": [
        {
            "type": "Paragraph",
            "raw": "This is a text",
            "range": [
                0,
                14
            ],
            "loc": {
                "start": {
                    "line": 1,
                    "column": 0
                },
                "end": {
                    "line": 1,
                    "column": 14
                }
            },
            "children": [
                {
                    "type": "Str",
                    "raw": "This is a text",
                    "range": [
                        0,
                        14
                    ],
                    "loc": {
                        "start": {
                            "line": 1,
                            "column": 0
                        },
                        "end": {
                            "line": 1,
                            "column": 14
                        }
                    }
                }
            ]
        },
        {
            "type": "Break",
            "raw": "\n",
            "range": [
                14,
                15
            ],
            "loc": {
                "start": {
                    "line": 1,
                    "column": 14
                },
                "end": {
                    "line": 1,
                    "column": 15
                }
            }
        },
        {
            "type": "Paragraph",
            "raw": "Parse text to AST",
            "range": [
                15,
                32
            ],
            "loc": {
                "start": {
                    "line": 2,
                    "column": 0
                },
                "end": {
                    "line": 2,
                    "column": 17
                }
            },
            "children": [
                {
                    "type": "Str",
                    "raw": "Parse text to AST",
                    "range": [
                        15,
                        32
                    ],
                    "loc": {
                        "start": {
                            "line": 2,
                            "column": 0
                        },
                        "end": {
                            "line": 2,
                            "column": 17
                        }
                    }
                }
            ]
        }
    ]
}
*/

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

14.0.4

2 months ago

14.0.3

3 months ago

14.0.2

3 months ago

14.0.1

3 months ago

14.0.0

3 months ago

13.4.2-next.0

3 months ago

13.4.1

5 months ago

13.3.3

10 months ago

13.4.0

6 months ago

13.3.2

1 year ago

13.3.1

1 year ago

13.1.3

1 year ago

13.1.4

1 year ago

13.1.1

1 year ago

13.3.0

1 year ago

13.1.2

1 year ago

13.1.0

1 year ago

13.0.5

1 year ago

13.2.0

1 year ago

12.6.1

1 year ago

12.6.0

1 year ago

13.0.4

1 year ago

13.0.2

1 year ago

13.0.3

1 year ago

13.0.0

1 year ago

13.0.1

1 year ago

12.5.2

1 year ago

12.3.0

1 year ago

12.5.0

1 year ago

12.2.3

1 year ago

12.2.2

2 years ago

12.2.1

2 years ago

12.2.0

2 years ago

12.1.1

2 years ago

12.1.0

2 years ago

12.0.2

3 years ago

12.0.0-beta.2

3 years ago

12.0.0-beta.3

3 years ago

12.0.0-beta.0

3 years ago

12.0.0-beta.1

3 years ago

12.0.0

3 years ago

3.3.5

3 years ago

3.3.4

3 years ago

3.3.3

3 years ago

3.3.2

3 years ago

3.3.1

3 years ago

3.3.0

3 years ago

3.2.5

3 years ago

3.2.2

4 years ago

3.2.1

4 years ago

3.2.0

4 years ago

3.2.4

4 years ago

3.2.3

4 years ago

3.1.7

4 years ago

3.1.6

5 years ago

3.1.5

5 years ago

3.1.4

5 years ago

3.1.3

5 years ago

3.1.2

5 years ago

3.1.1

5 years ago

3.1.0

5 years ago

3.0.9

6 years ago

3.0.8

6 years ago

3.0.7

6 years ago

3.0.6

6 years ago

3.0.5

6 years ago

3.0.4

6 years ago

3.0.3

6 years ago