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 17, 2017
1 parent 685a354 commit 64d41f3
Showing 1 changed file with 37 additions and 8 deletions.
45 changes: 37 additions & 8 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,20 +15,49 @@ npm install remark-slug

## Usage

```javascript
var slug = require('./');
var remark = require('remark');
var html = require('remark-html');
Say we have the following file, `example.md`:

```markdown
# Lorem ipsum 😪

## dolor—sit—amet

### consectetur & adipisicing

var file = remark().use(slug).use(html).processSync('# Foo bar');
#### elit

console.log(String(file));
##### elit
```

And our script, `example.js`, looks as follows:

```javascript
var fs = require('fs');
var unified = require('unified');
var markdown = require('remark-parse');
var slug = require('remark-slug');
var remark2rehype = require('remark-rehype');
var html = require('rehype-stringify');

unified()
.use(markdown)
.use(slug)
.use(remark2rehype)
.use(html)
.process(fs.readFileSync('example.md'), function (err, file) {
if (err) throw err;
console.log(String(file));
});
```

Yields:
Now, running `node example` yields:

```html
<h1 id="foo-bar">Foo bar</h1>
<h1 id="lorem-ipsum-">Lorem ipsum 😪</h1>
<h2 id="dolorsitamet">dolor—sit—amet</h2>
<h3 id="consectetur--adipisicing">consectetur &#x26; adipisicing</h3>
<h4 id="elit">elit</h4>
<h5 id="elit-1">elit</h5>
```

## API
Expand Down

0 comments on commit 64d41f3

Please sign in to comment.