Browse Source

Fix emphasis matching where delimiters are multiple of 3

This is now allowed as per commonmark 0.29 spec:
ex***amp***le

See also:
83ed53e12a

fix https://github.com/markdown-it/markdown-it/issues/561
pull/570/head
Alex Kocharin 5 years ago
parent
commit
e519e6ac19
  1. 19
      lib/rules_inline/balance_pairs.js
  2. 28
      test/fixtures/commonmark/bad.txt
  3. 18
      test/fixtures/commonmark/good.txt

19
lib/rules_inline/balance_pairs.js

@ -23,11 +23,22 @@ module.exports = function link_pairs(state) {
currDelim.end < 0 &&
currDelim.level === lastDelim.level) {
var odd_match = false;
// typeofs are for backward compatibility with plugins
var odd_match = (currDelim.close || lastDelim.open) &&
typeof currDelim.length !== 'undefined' &&
typeof lastDelim.length !== 'undefined' &&
(currDelim.length + lastDelim.length) % 3 === 0;
if ((currDelim.close || lastDelim.open) &&
typeof currDelim.length !== 'undefined' &&
typeof lastDelim.length !== 'undefined') {
// from spec:
// sum of the lengths [...] must not be a multiple of 3
// unless both lengths are multiples of 3
if ((currDelim.length + lastDelim.length) % 3 === 0) {
if (currDelim.length % 3 !== 0 || lastDelim.length % 3 !== 0) {
odd_match = true;
}
}
}
if (!odd_match) {
lastDelim.jump = i - j;

28
test/fixtures/commonmark/bad.txt

@ -65,31 +65,3 @@ error:
</ol>
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
src line: 6912
.
foo***bar***baz
.
<p>foo<em><strong>bar</strong></em>baz</p>
.
error:
<p>foo***bar***baz</p>
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
src line: 6918
.
foo******bar*********baz
.
<p>foo<strong><strong><strong>bar</strong></strong></strong>***baz</p>
.
error:
<p>foo******bar*********baz</p>

18
test/fixtures/commonmark/good.txt

@ -5432,6 +5432,24 @@ src line: 6901
<p><em>foo<strong>bar</strong></em></p>
.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
src line: 6912
.
foo***bar***baz
.
<p>foo<em><strong>bar</strong></em>baz</p>
.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
src line: 6918
.
foo******bar*********baz
.
<p>foo<strong><strong><strong>bar</strong></strong></strong>***baz</p>
.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
src line: 6927

Loading…
Cancel
Save