Browse Source

Fix em- and en-dashes not being typographed when separated by 1 char

close https://github.com/markdown-it/markdown-it/issues/624
pull/652/head
Alex Kocharin 5 years ago
parent
commit
3c427f921e
  1. 6
      lib/rules_core/replacements.js
  2. 20
      test/fixtures/markdown-it/tables.txt
  3. 13
      test/fixtures/markdown-it/typographer.txt

6
lib/rules_core/replacements.js

@ -68,10 +68,10 @@ function replace_rare(inlineTokens) {
.replace(/\.{2,}/g, '…').replace(/([?!])…/g, '$1..') .replace(/\.{2,}/g, '…').replace(/([?!])…/g, '$1..')
.replace(/([?!]){4,}/g, '$1$1$1').replace(/,{2,}/g, ',') .replace(/([?!]){4,}/g, '$1$1$1').replace(/,{2,}/g, ',')
// em-dash // em-dash
.replace(/(^|[^-])---([^-]|$)/mg, '$1\u2014$2') .replace(/(^|[^-])---(?=[^-]|$)/mg, '$1\u2014')
// en-dash // en-dash
.replace(/(^|\s)--(\s|$)/mg, '$1\u2013$2') .replace(/(^|\s)--(?=\s|$)/mg, '$1\u2013')
.replace(/(^|[^-\s])--([^-\s]|$)/mg, '$1\u2013$2'); .replace(/(^|[^-\s])--(?=[^-\s]|$)/mg, '$1\u2013');
} }
} }

20
test/fixtures/markdown-it/tables.txt

@ -168,11 +168,11 @@ bar|bar
Second line should not contain symbols except "-", ":", "|" and " ": Second line should not contain symbols except "-", ":", "|" and " ":
. .
foo|foo foo|foo
---|---s -----|-----s
bar|bar bar|bar
. .
<p>foo|foo <p>foo|foo
—|---s -----|-----s
bar|bar</p> bar|bar</p>
. .
@ -180,11 +180,11 @@ bar|bar</p>
Second line should contain "|" symbol: Second line should contain "|" symbol:
. .
foo|foo foo|foo
---:--- -----:-----
bar|bar bar|bar
. .
<p>foo|foo <p>foo|foo
—:--- -----:-----
bar|bar</p> bar|bar</p>
. .
@ -192,11 +192,11 @@ bar|bar</p>
Second line should not have empty columns in the middle: Second line should not have empty columns in the middle:
. .
foo|foo foo|foo
---||--- -----||-----
bar|bar bar|bar
. .
<p>foo|foo <p>foo|foo
—||— -----||-----
bar|bar</p> bar|bar</p>
. .
@ -204,11 +204,11 @@ bar|bar</p>
Wrong alignment symbol position: Wrong alignment symbol position:
. .
foo|foo foo|foo
---|-::- -----|-::-
bar|bar bar|bar
. .
<p>foo|foo <p>foo|foo
|-::- -----|-::-
bar|bar</p> bar|bar</p>
. .
@ -216,11 +216,11 @@ bar|bar</p>
Title line should contain "|" symbol: Title line should contain "|" symbol:
. .
foo foo
---|--- -----|-----
bar|bar bar|bar
. .
<p>foo <p>foo
—|--- -----|-----
bar|bar</p> bar|bar</p>
. .

13
test/fixtures/markdown-it/typographer.txt

@ -79,3 +79,16 @@ markdownit--awesome
<p>–markdownit – super–</p> <p>–markdownit – super–</p>
<p>markdownit–awesome</p> <p>markdownit–awesome</p>
. .
regression tests for #624
.
1---2---3
1--2--3
1 -- -- 3
.
<p>1—2—3</p>
<p>1–2–3</p>
<p>1 – – 3</p>
.

Loading…
Cancel
Save