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 12, 2017
1 parent cffa52c commit 7286f44
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 113 deletions.
72 changes: 23 additions & 49 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,68 +17,42 @@ Algorithms that work on regular unist trees are (mostly) guaranteed to worked on

## Examples

Follow parent links:
Say `example.md` looks as follows:

```js
var ast = mdast.parse('- top-level item\n' +
' - subitem 1\n' +
' - subitem 2\n');
```markdown
* top-level item

* subitem 1
* subitem 2
```

...and to follow parent links, our `example.js` looks like this:

```javascript
var vfile = require('to-vfile');
var unified = require('unified');
var parse = require('remark-parse');
var parents = require('unist-util-parents');

var file = vfile.readSync('example.md');
var tree = unified().use(parse).parse(file);

// "subitem 2"
var item = parents(ast).children[0].children[0].children[1].children[1];
var item = parents(tree).children[0].children[0].children[1].children[1];

var chain = [];
while (item) {
chain.unshift(item.type);
item = item.parent;
}
chain
//=> [ 'root', 'list', 'listItem', 'list', 'listItem' ]
```

Unwrap all `emphasis` and `strong` nodes:

```js
var parents = require('unist-util-parents'),
select = require('unist-util-select');

select(parents(ast), 'emphasis, strong').forEach(function (em) {
var siblings = em.parent.node.children;
var index = siblings.indexOf(em.node);
[].splice.apply(siblings, [index, 1].concat(em.node.children));
});
console.log(chain);
```

input:

```md
# Drop highlight

Drop __all__ the [*emphasis*][1] and **[bold][1]** highlighting, leaving

| _everything_ |
| :----------: |
| `else` |

## __intact__

[1]: https://ddg.gg/?q=emphasis
```

output:

```md
# Drop highlight

Drop all the [emphasis][1] and [bold][1] highlighting, leaving

| everything |
| :--------: |
| `else` |

## intact
Yields:

[1]: https://ddg.gg/?q=emphasis
```javascript
[ 'root', 'list', 'listItem', 'list', 'listItem' ]
```

## API
Expand Down
11 changes: 0 additions & 11 deletions example/doc.md

This file was deleted.

21 changes: 0 additions & 21 deletions example/index.js

This file was deleted.

19 changes: 0 additions & 19 deletions example/list.js

This file was deleted.

13 changes: 0 additions & 13 deletions example/package.json

This file was deleted.

0 comments on commit 7286f44

Please sign in to comment.