Browse Source

Typhgrapher - updated dashes behaviour

pull/14/head
Vitaly Puzrin 10 years ago
parent
commit
8a2367f678
  1. 2
      lib/defaults/typographer.js
  2. 9
      lib/rules_typographer/replace.js
  3. 20
      test/fixtures/remarkable/typographer.txt

2
lib/defaults/typographer.js

@ -13,5 +13,5 @@ module.exports = {
paragraph: true, // (p) (P) → § paragraph: true, // (p) (P) → §
ellipsis: true, // ... → … ellipsis: true, // ... → …
dupes: true, // ???????? → ???, !!!!! → !!!, `,,` → `,` dupes: true, // ???????? → ???, !!!!! → !!!, `,,` → `,`
emDashes: true // -- → — dashes: true // -- → —
}; };

9
lib/rules_typographer/replace.js

@ -42,8 +42,13 @@ module.exports = function replace(t, state) {
text.indexOf(',,') >= 0)) { text.indexOf(',,') >= 0)) {
text = text.replace(/([?!]){4,}/g, '$1$1$1').replace(/,{2,}/g, ','); text = text.replace(/([?!]){4,}/g, '$1$1$1').replace(/,{2,}/g, ',');
} }
if (options.emDashes && text.indexOf('--') >= 0) { if (options.dashes && text.indexOf('--') >= 0) {
text = text.replace(/(^|\s)--(\s|$)/mg, '$1—$2'); text = text
// em-dash
.replace(/(^|[^-])---([^-]|$)/mg, '$1\u2014$2')
// en-dash
.replace(/(^|\s)--(\s|$)/mg, '$1\u2013$2')
.replace(/(^|[^-\s])--([^-\s]|$)/mg, '$1\u2013$2');
} }
token.content = text; token.content = text;

20
test/fixtures/remarkable/typographer.txt

@ -54,14 +54,30 @@ dupes
. .
em-dashes dashes
. .
-- remarkable -- super -- ---remarkable --- super---
remarkable---awesome
abc ----
. .
<p>—remarkable — super—</p> <p>—remarkable — super—</p>
<p>remarkable—awesome</p>
<p>abc ----</p>
.
.
--remarkable -- super--
remarkable--awesome
.
<p>–remarkable – super–</p>
<p>remarkable–awesome</p>
. .
TODO: TODO:
- "Monitor 21"" - "Monitor 21""
Loading…
Cancel
Save