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 4 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(/([?!]){4,}/g, '$1$1$1').replace(/,{2,}/g, ',')
// em-dash
.replace(/(^|[^-])---([^-]|$)/mg, '$1\u2014$2')
.replace(/(^|[^-])---(?=[^-]|$)/mg, '$1\u2014')
// en-dash
.replace(/(^|\s)--(\s|$)/mg, '$1\u2013$2')
.replace(/(^|[^-\s])--([^-\s]|$)/mg, '$1\u2013$2');
.replace(/(^|\s)--(?=\s|$)/mg, '$1\u2013')
.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 " ":
.
foo|foo
---|---s
-----|-----s
bar|bar
.
<p>foo|foo
—|---s
-----|-----s
bar|bar</p>
.
@ -180,11 +180,11 @@ bar|bar</p>
Second line should contain "|" symbol:
.
foo|foo
---:---
-----:-----
bar|bar
.
<p>foo|foo
—:---
-----:-----
bar|bar</p>
.
@ -192,11 +192,11 @@ bar|bar</p>
Second line should not have empty columns in the middle:
.
foo|foo
---||---
-----||-----
bar|bar
.
<p>foo|foo
—||—
-----||-----
bar|bar</p>
.
@ -204,11 +204,11 @@ bar|bar</p>
Wrong alignment symbol position:
.
foo|foo
---|-::-
-----|-::-
bar|bar
.
<p>foo|foo
|-::-
-----|-::-
bar|bar</p>
.
@ -216,11 +216,11 @@ bar|bar</p>
Title line should contain "|" symbol:
.
foo
---|---
-----|-----
bar|bar
.
<p>foo
—|---
-----|-----
bar|bar</p>
.

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

@ -79,3 +79,16 @@ markdownit--awesome
<p>–markdownit – super–</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