diff --git a/lib/rules_inline/balance_pairs.js b/lib/rules_inline/balance_pairs.js index 4ec2845..f2a5207 100644 --- a/lib/rules_inline/balance_pairs.js +++ b/lib/rules_inline/balance_pairs.js @@ -23,11 +23,19 @@ module.exports = function link_pairs(state) { currDelim.end < 0 && currDelim.level === lastDelim.level) { - lastDelim.jump = i - j; - lastDelim.open = false; - currDelim.end = i; - currDelim.jump = 0; - break; + // 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.open = false; + currDelim.end = i; + currDelim.jump = 0; + break; + } } j -= currDelim.jump + 1; diff --git a/lib/rules_inline/emphasis.js b/lib/rules_inline/emphasis.js index fa26e61..31bfbdd 100644 --- a/lib/rules_inline/emphasis.js +++ b/lib/rules_inline/emphasis.js @@ -25,6 +25,10 @@ module.exports.tokenize = function emphasis(state, silent) { // marker: marker, + // Total length of these series of delimiters. + // + length: scanned.length, + // An amount of characters before this one that's equivalent to // current one. In plain English: if this delimiter does not open // an emphasis, neither do previous `jump` characters. diff --git a/test/fixtures/commonmark/bad.txt b/test/fixtures/commonmark/bad.txt index 0ed2fd6..63aa4ef 100644 --- a/test/fixtures/commonmark/bad.txt +++ b/test/fixtures/commonmark/bad.txt @@ -242,59 +242,3 @@ error: -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -src line: 6546 - -. -*foo**bar**baz* -. -
foobarbaz
-. - -error: - -foobarbaz
- - -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -src line: 6585 - -. -*foo**bar*** -. -foobar
-. - -error: - -foobar**
- - -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -src line: 6592 - -. -*foo**bar*** -. -foobar
-. - -error: - -foobar**
- - -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -src line: 6690 - -. -**foo*bar*baz** -. -foobarbaz
-. - -error: - -foobarbaz**
- - diff --git a/test/fixtures/commonmark/good.txt b/test/fixtures/commonmark/good.txt index 39c53bb..9553737 100644 --- a/test/fixtures/commonmark/good.txt +++ b/test/fixtures/commonmark/good.txt @@ -5001,6 +5001,15 @@ src line: 6540foo bar baz
. +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +src line: 6546 + +. +*foo**bar**baz* +. +foobarbaz
+. + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ src line: 6571 @@ -5019,6 +5028,24 @@ src line: 6578foo bar
. +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +src line: 6585 + +. +*foo**bar*** +. +foobar
+. + +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +src line: 6592 + +. +*foo**bar*** +. +foobar
+. + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ src line: 6600 @@ -5120,6 +5147,15 @@ src line: 6683foo bar baz
. +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +src line: 6690 + +. +**foo*bar*baz** +. +foobarbaz
+. + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ src line: 6697