diff --git a/readme.md b/readme.md index d06445f..04fa77c 100644 --- a/readme.md +++ b/readme.md @@ -14,19 +14,30 @@ npm install mdast-util-to-hast ## Usage +Say we have the following `example.md`: + +```markdown +## Hello **World**! +``` + +...and next to it, `example.js`: + ```javascript var inspect = require('unist-util-inspect'); -var remark = require('remark'); +var unified = require('unified'); +var parse = require('remark-parse'); +var vfile = require('to-vfile'); var toHAST = require('mdast-util-to-hast'); -var hast = toHAST(remark().parse('## Hello **World**!')); -console.log(inspect(hast)); +var tree = unified().use(parse).parse(vfile.readSync('example.md')); + +console.log(inspect(toHAST(tree))); ``` -Yields: +Which when running with `node example` yields: ```txt -root[1] (1:1-1:20, 0-19) +root[1] (1:1-2:1, 0-20) └─ element[3] (1:1-1:20, 0-19) [tagName="h2"] ├─ text: "Hello " (1:4-1:10, 3-9) ├─ element[1] (1:10-1:19, 9-18) [tagName="strong"]