mdast utility to transform markdown into nlcst, while keeping location information intact.
In plain English: this enables natural-language tooling to read markdown as input.
Note You probably want to use remark-retext.
npm:
npm install mdast-util-to-nlcstmdast-util-to-nlcst is also available for bower, component, and duo, and as an AMD, CommonJS, and globals module, uncompressed and compressed.
var toNLCST = require('mdast-util-to-nlcst'); var inspect = require('unist-util-inspect'); var remark = require('remark'); var retext = require('retext'); /* * Process. */ remark().process('Some *foo*s-_ball_.', function (err, file) { var tree = toNLCST(file, retext().Parser); console.log(inspect(tree)); /* * Yields: * * RootNode[1] (1:1-1:20, 0-19) * └─ ParagraphNode[1] (1:1-1:20, 0-19) * └─ SentenceNode[4] (1:1-1:20, 0-19) * ├─ WordNode[1] (1:1-1:5, 0-4) * │ └─ TextNode: "Some" (1:1-1:5, 0-4) * ├─ WhiteSpaceNode: " " (1:5-1:6, 4-5) * ├─ WordNode[4] (1:7-1:18, 6-17) * │ ├─ TextNode: "foo" (1:7-1:10, 6-9) * │ ├─ TextNode: "s" (1:11-1:12, 10-11) * │ ├─ PunctuationNode: "-" (1:12-1:13, 11-12) * │ └─ TextNode: "ball" (1:14-1:18, 13-17) * └─ PunctuationNode: "." (1:19-1:20, 18-19) */ });Transform a by remark processed virtual file into an NLCST tree for retext.
Parameters:
-
file(File) — Virtual file, must be passed throughparse(). -
parser(FunctionorParser, optional) — You can pass the (constructor of) an NLCST parser, such as parse-english, parse-dutch, or parse-latin.
Returns: