Skip to content

Commit

Permalink
Update example
Browse files Browse the repository at this point in the history
  • Loading branch information
wooorm committed Jul 15, 2021
1 parent 3122102 commit 080034f
Showing 1 changed file with 22 additions and 15 deletions.
37 changes: 22 additions & 15 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,22 +36,29 @@ And our script, `example.js`, looks as follows:
```js
import {toVFile} from 'to-vfile'
import {reporter} from 'vfile-reporter'
import {remark} from 'remark'
import {messageControl} from 'unified-message-control'
import {commentMarker} from 'mdast-comment-marker'

remark()
.use(warn)
.use(messageControl, {name: 'foo', marker: commentMarker, test: 'html'})
.process(toVFile.readSync('example.md'), function (err, file) {
console.error(reporter(err || file))
})

function warn() {
return function (tree, file) {
file.message('Whoops!', tree.children[1], 'foo:thing')
}
}
import {unified} from 'unified'
import unifiedMessageControl from 'unified-message-control'
import remarkParse from 'remark-parse'
import remarkStringify from 'remark-stringify'

toVFile.read('example.md').then((file) => {
unified()
.use(remarkParse)
.use(remarkStringify)
.use(() => (tree, file) => {
file.message('Whoops!', tree.children[1], 'foo:thing')
})
.use(unifiedMessageControl, {
name: 'foo',
marker: commentMarker,
test: 'html'
})
.process(file)
.then((file) => {
console.error(reporter(file))
})
})
```

Now, running `node example` yields:
Expand Down

0 comments on commit 080034f

Please sign in to comment.