Browse Source

Implement odd matching rules for emphasis

pull/293/head
Alex Kocharin 8 years ago
parent
commit
f07d3862ff
  1. 8
      lib/rules_inline/balance_pairs.js
  2. 4
      lib/rules_inline/emphasis.js
  3. 56
      test/fixtures/commonmark/bad.txt
  4. 36
      test/fixtures/commonmark/good.txt

8
lib/rules_inline/balance_pairs.js

@ -23,12 +23,20 @@ module.exports = function link_pairs(state) {
currDelim.end < 0 && currDelim.end < 0 &&
currDelim.level === lastDelim.level) { currDelim.level === lastDelim.level) {
// 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 (!odd_match) {
lastDelim.jump = i - j; lastDelim.jump = i - j;
lastDelim.open = false; lastDelim.open = false;
currDelim.end = i; currDelim.end = i;
currDelim.jump = 0; currDelim.jump = 0;
break; break;
} }
}
j -= currDelim.jump + 1; j -= currDelim.jump + 1;
} }

4
lib/rules_inline/emphasis.js

@ -25,6 +25,10 @@ module.exports.tokenize = function emphasis(state, silent) {
// //
marker: marker, marker: marker,
// Total length of these series of delimiters.
//
length: scanned.length,
// An amount of characters before this one that's equivalent to // An amount of characters before this one that's equivalent to
// current one. In plain English: if this delimiter does not open // current one. In plain English: if this delimiter does not open
// an emphasis, neither do previous `jump` characters. // an emphasis, neither do previous `jump` characters.

56
test/fixtures/commonmark/bad.txt

@ -242,59 +242,3 @@ error:
</ul> </ul>
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
src line: 6546
.
*foo**bar**baz*
.
<p><em>foo<strong>bar</strong>baz</em></p>
.
error:
<p><em>foo</em><em>bar</em><em>baz</em></p>
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
src line: 6585
.
*foo**bar***
.
<p><em>foo<strong>bar</strong></em></p>
.
error:
<p><em>foo</em><em>bar</em>**</p>
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
src line: 6592
.
*foo**bar***
.
<p><em>foo<strong>bar</strong></em></p>
.
error:
<p><em>foo</em><em>bar</em>**</p>
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
src line: 6690
.
**foo*bar*baz**
.
<p><strong>foo<em>bar</em>baz</strong></p>
.
error:
<p><em><em>foo</em>bar</em>baz**</p>

36
test/fixtures/commonmark/good.txt

@ -5001,6 +5001,15 @@ src line: 6540
<p><em>foo <strong>bar</strong> baz</em></p> <p><em>foo <strong>bar</strong> baz</em></p>
. .
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
src line: 6546
.
*foo**bar**baz*
.
<p><em>foo<strong>bar</strong>baz</em></p>
.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
src line: 6571 src line: 6571
@ -5019,6 +5028,24 @@ src line: 6578
<p><em>foo <strong>bar</strong></em></p> <p><em>foo <strong>bar</strong></em></p>
. .
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
src line: 6585
.
*foo**bar***
.
<p><em>foo<strong>bar</strong></em></p>
.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
src line: 6592
.
*foo**bar***
.
<p><em>foo<strong>bar</strong></em></p>
.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
src line: 6600 src line: 6600
@ -5120,6 +5147,15 @@ src line: 6683
<p><strong>foo <em>bar</em> baz</strong></p> <p><strong>foo <em>bar</em> baz</strong></p>
. .
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
src line: 6690
.
**foo*bar*baz**
.
<p><strong>foo<em>bar</em>baz</strong></p>
.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
src line: 6697 src line: 6697

Loading…
Cancel
Save