cmark

My personal build of CMark ✏️

Commit
2cf0750a7a507eded4cf3c9a48fd1f924d0ce538
Parent
3c89f2660280266d9d82cf398b2ff9ba5d693fff
Author
John MacFarlane <fiddlosopher@gmail.com>
Date

Fixed #48.

- Fixed js and C code. - Added two test cases to spec.

Diffstat

3 files changed, 26 insertions, 7 deletions

Status File Name N° Changes Insertions Deletions
Modified js/stmd.js 11 5 6
Modified spec.txt 12 12 0
Modified src/inlines.c 10 9 1
diff --git a/js/stmd.js b/js/stmd.js
@@ -341,16 +341,15 @@ var parseEmphasis = function(inlines) {
       res = this.scanDelims(c);
       if (res.numdelims >= 1 && res.numdelims <= 3 && res.can_close &&
             res.numdelims != first_close_delims) {
-        if (res.numdelims === 3) {
-          // If we opened with ***, then we interpret *** as ** followed by *
-          // giving us <strong><em>
-          res.numdelims = 1;
-        }
 
-        if (first_close_delims === 1) {
+        if (first_close_delims === 1 && numdelims > 2) {
           res.numdelims = 2;
         } else if (first_close_delims === 2) {
           res.numdelims = 1;
+        } else if (res.numdelims === 3) {
+          // If we opened with ***, then we interpret *** as ** followed by *
+          // giving us <strong><em>
+          res.numdelims = 1;
         }
 
         this.pos += res.numdelims;
diff --git a/spec.txt b/spec.txt
@@ -4561,6 +4561,18 @@ similarly for `_` and `__`):
 <p><strong>foo</strong>*</p>
 .
 
+.
+***foo* bar***
+.
+<p><strong><em>foo</em> bar</strong>*</p>
+.
+
+.
+***foo** bar***
+.
+<p><em><strong>foo</strong> bar</em>**</p>
+.
+
 The following contains no strong emphasis, because the opening
 delimiter is closed by the first `*` before `bar`:
 
diff --git a/src/inlines.c b/src/inlines.c
@@ -425,9 +425,17 @@ static inl* handle_strong_emph(subject* subj, char c)
         new = make_str(bmidstr(subj->buffer, subj->pos, numdelims));
         append_inlines(*last, new);
         *last = new;
-        if (numdelims == 3) {
+
+        if (first_close_delims == 1 && numdelims > 2) {
+          numdelims = 2;
+        } else if (first_close_delims == 2) {
+          numdelims = 1;
+        } else if (numdelims == 3) {
+          // If we opened with ***, we interpret it as ** followed by *
+          // giving us <strong><em>
           numdelims = 1;
         }
+
         subj->pos += numdelims;
         if (first_close) {
           first_head->tag = first_close_delims == 1 ? strong : emph;