Skip to content

Commit

Permalink
Refactor examples in readme.md
Browse files Browse the repository at this point in the history
  • Loading branch information
wooorm committed May 27, 2017
1 parent d9502f3 commit b7d893a
Showing 1 changed file with 44 additions and 28 deletions.
72 changes: 44 additions & 28 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,62 +14,78 @@ npm install retext-quotes

## Usage

Say we have the following file, `example.txt`:

```text
A sentence "with quotes, 'nested' quotes,
and '80s apostrophes."
```

And our script, `example.js`, looks like this:

```javascript
var retext = require('retext');
var vfile = require('to-vfile');
var report = require('vfile-reporter');
var unified = require('unified');
var english = require('retext-english');
var stringify = require('retext-stringify');
var quotes = require('retext-quotes');
var report = require('vfile-reporter');

retext().use(english).use(quotes).process([
'A sentence "with quotes, \'nested\' quotes,',
'and \'80s apostrophes."'
].join('\n'), function (err, file) {
console.log(report(err || file));
});
unified()
.use(english)
.use(quotes)
.use(stringify)
.process(vfile.readSync('example.txt'), function (err, file) {
console.error(report(err || file));
});
```

Yields:
Now, running `node example` yields:

```text
1:12-1:13 warning Expected a smart quote: `“`, not `"` quote
1:26-1:27 warning Expected a smart quote: `‘`, not `'` quote
1:33-1:34 warning Expected a smart quote: `’`, not `'` quote
2:5-2:6 warning Expected a smart apostrophe: `’`, not `'` apostrophe
2:22-2:23 warning Expected a smart quote: `”`, not `"` quote
example.txt
1:12-1:13 warning Expected a smart quote: `“`, not `"` quote retext-quotes
1:26-1:27 warning Expected a smart quote: `‘`, not `'` quote retext-quotes
1:33-1:34 warning Expected a smart quote: `’`, not `'` quote retext-quotes
2:5-2:6 warning Expected a smart apostrophe: `’`, not `'` apostrophe retext-quotes
2:22-2:23 warning Expected a smart quote: `”`, not `"` quote retext-quotes
⚠ 5 warnings
```

This plugin can be configured to prefer “straight” quotes instead:

```diff
-retext().use(english).use(quotes).process([
+retext().use(english).use(quotes, {preferred: 'straight'}).process([
'A sentence "with quotes, \'nested\' quotes,',
.use(english)
- .use(quotes)
+ .use(quotes, {preferred: 'straight'})
.use(stringify)
```

Yields:
Now, running `node example` again would yield:

```text
no issues found
```

Or, pass in different markers that count as “smart”:
You can also pass in different markers that count as “smart”:

```diff
-retext().use(english).use(quotes).process([
+retext().use(english).use(quotes, {smart: ['«»', '‹›']}).process([
'A sentence "with quotes, \'nested\' quotes,',
.use(english)
- .use(quotes)
+ .use(quotes, {smart: ['«»', '‹›']})
.use(stringify)
```

Yields:
Running `node example` a final time yields:

```text
1:12-1:13 warning Expected a smart quote: `«`, not `"` quote
1:26-1:27 warning Expected a smart quote: `‹`, not `'` quote
1:33-1:34 warning Expected a smart quote: `›`, not `'` quote
2:5-2:6 warning Expected a smart apostrophe: `’`, not `'` apostrophe
2:22-2:23 warning Expected a smart quote: `»`, not `"` quote
example.txt
1:12-1:13 warning Expected a smart quote: `«`, not `"` quote retext-quotes
1:26-1:27 warning Expected a smart quote: `‹`, not `'` quote retext-quotes
1:33-1:34 warning Expected a smart quote: `›`, not `'` quote retext-quotes
2:5-2:6 warning Expected a smart apostrophe: `’`, not `'` apostrophe retext-quotes
2:22-2:23 warning Expected a smart quote: `»`, not `"` quote retext-quotes
⚠ 5 warnings
```
Expand Down

0 comments on commit b7d893a

Please sign in to comment.