Skip to content

Commit

Permalink
Update example in readme.md
Browse files Browse the repository at this point in the history
  • Loading branch information
wooorm committed Jun 13, 2017
1 parent 9fc1a20 commit 88e406b
Showing 1 changed file with 16 additions and 5 deletions.
21 changes: 16 additions & 5 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
Expand Down

0 comments on commit 88e406b

Please sign in to comment.