Check quotes and apostrophes, and warn if their style ("straight"
or
“smart”
) or level of nesting is not the preferred style. All with
retext.
npm:
npm install retext-quotes
var retext = require('retext');
var english = require('retext-english');
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));
});
Yields:
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
⚠ 5 warnings
This plugin can be configured to prefer “straight” quotes instead:
-retext().use(english).use(quotes).process([
+retext().use(english).use(quotes, {preferred: 'straight'}).process([
'A sentence "with quotes, \'nested\' quotes,',
Yields:
no issues found
Or, pass in different markers that count as “smart”:
-retext().use(english).use(quotes).process([
+retext().use(english).use(quotes, {smart: ['«»', '‹›']}).process([
'A sentence "with quotes, \'nested\' quotes,',
Yields:
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
⚠ 5 warnings
Emit warnings when the use of quotes doesn’t match the preferred style.
This plug-in knows about apostrophes as well and prefers '
when
preferred: 'straight'
, and ’
otherwise.
The values in straight
and smart
can be one or two characters.
When two, the first character determines the opening quote and the
second the closing quote at that level. When one, both the opening
and closing quote are that character.
Additionally, the order in which the preferred quotes appear in their
respective list determines which quotes to use at which level of nesting.
So, to prefer ‘’
at the first level of nesting, and “”
at the second,
pass: smart: ['‘’', '“”']
.
If quotes are nested deeper than the given amount of quotes, the markers
wrap around: a third level of nesting when using smart: ['«»', '‹›']
should have double guillemets, a fourth single, a fifth double again, etc.
preferred
('smart'
or'straight'
, default:'smart'
) — Style of quotes to preferstraight
(Array.<string>
, default:['"', '\'']
) — List of quotes to see as “straight”smart
(Array.<string>
, default:['“”', '‘’']
) — List of quotes to see as “smart”
retext-contractions
— Check apostrophe use in contractionsretext-diacritics
— Check for proper use of diacriticsretext-sentence-spacing
— Check spacing (one or two spaces) between sentences