From eed156e9cd8f9db123e7fb227d40fff052dffac2 Mon Sep 17 00:00:00 2001 From: Alex Kocharin Date: Wed, 30 Jun 2021 18:56:12 +0300 Subject: [PATCH] Fix emphasis algorithm as per 0.30 spec https://github.com/commonmark/cmark/issues/383 --- lib/rules_inline/balance_pairs.js | 10 ++++++---- test/fixtures/markdown-it/commonmark_extras.txt | 7 +++++++ 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/lib/rules_inline/balance_pairs.js b/lib/rules_inline/balance_pairs.js index bd8355085..c6ee5a78d 100644 --- a/lib/rules_inline/balance_pairs.js +++ b/lib/rules_inline/balance_pairs.js @@ -21,12 +21,14 @@ function processDelimiters(state, delimiters) { if (!closer.close) continue; // Previously calculated lower bounds (previous fails) - // for each marker and each delimiter length modulo 3. + // for each marker, each delimiter length modulo 3, + // and for whether this closer can be an opener; + // https://github.com/commonmark/cmark/commit/34250e12ccebdc6372b8b49c44fab57c72443460 if (!openersBottom.hasOwnProperty(closer.marker)) { - openersBottom[closer.marker] = [ -1, -1, -1 ]; + openersBottom[closer.marker] = [ -1, -1, -1, -1, -1, -1 ]; } - minOpenerIdx = openersBottom[closer.marker][closer.length % 3]; + minOpenerIdx = openersBottom[closer.marker][(closer.open ? 3 : 0) + (closer.length % 3)]; openerIdx = closerIdx - closer.jump - 1; @@ -87,7 +89,7 @@ function processDelimiters(state, delimiters) { // See details here: // https://github.com/commonmark/cmark/issues/178#issuecomment-270417442 // - openersBottom[closer.marker][(closer.length || 0) % 3] = newMinOpenerIdx; + openersBottom[closer.marker][(closer.open ? 3 : 0) + ((closer.length || 0) % 3)] = newMinOpenerIdx; } } } diff --git a/test/fixtures/markdown-it/commonmark_extras.txt b/test/fixtures/markdown-it/commonmark_extras.txt index 6568d3dc2..d884b0589 100644 --- a/test/fixtures/markdown-it/commonmark_extras.txt +++ b/test/fixtures/markdown-it/commonmark_extras.txt @@ -1,3 +1,10 @@ +Issue commonmark/cmark#383: +. +*****Hello*world**** +. +

**Helloworld

+. + Issue #246. Double escaping in ALT . ![&](#)