txt-to-ast
Parse plain text to AST with location info.
This library is a part of textlint/textlint.
Markdown version : markdown-to-ast
The AST consists of TxtNode
s.
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 araw
text.value
- Node have avalue
of text.
The interface are defined in textlint/txtnode.md
This library is a part of textlint/textlint.
Installation
npm install txt-to-ast
DEMO
Try to http://azu.github.io/txt-to-ast/example/
Usage
var parse = parse;var text = "This is a text\nParse text to AST";var AST = ;console/*{ "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
- Fork it!
- Create your feature branch:
git checkout -b my-new-feature
- Commit your changes:
git commit -am 'Add some feature'
- Push to the branch:
git push origin my-new-feature
- Submit a pull request :D
License
MIT