diff --git a/lib/defaults/typographer.js b/lib/defaults/typographer.js index 8885f3c..1b660fe 100644 --- a/lib/defaults/typographer.js +++ b/lib/defaults/typographer.js @@ -13,5 +13,5 @@ module.exports = { paragraph: true, // (p) (P) → § ellipsis: true, // ... → … dupes: true, // ???????? → ???, !!!!! → !!!, `,,` → `,` - emDashes: true // -- → — + dashes: true // -- → — }; diff --git a/lib/rules_typographer/replace.js b/lib/rules_typographer/replace.js index 2512296..b895f47 100644 --- a/lib/rules_typographer/replace.js +++ b/lib/rules_typographer/replace.js @@ -42,8 +42,13 @@ module.exports = function replace(t, state) { text.indexOf(',,') >= 0)) { text = text.replace(/([?!]){4,}/g, '$1$1$1').replace(/,{2,}/g, ','); } - if (options.emDashes && text.indexOf('--') >= 0) { - text = text.replace(/(^|\s)--(\s|$)/mg, '$1—$2'); + if (options.dashes && text.indexOf('--') >= 0) { + 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; diff --git a/test/fixtures/remarkable/typographer.txt b/test/fixtures/remarkable/typographer.txt index f144f82..e49381d 100644 --- a/test/fixtures/remarkable/typographer.txt +++ b/test/fixtures/remarkable/typographer.txt @@ -54,14 +54,30 @@ dupes . -em-dashes +dashes +. +---remarkable --- super--- + +remarkable---awesome + +abc ---- +. +

—remarkable — super—

+

remarkable—awesome

+

abc ----

. --- remarkable -- super -- . -

— remarkable — super —

+--remarkable -- super-- + +remarkable--awesome +. +

–remarkable – super–

+

remarkable–awesome

. + + TODO: - "Monitor 21"" \ No newline at end of file