Commit a847f5522e7129f529aa96ec34ba340effb25afe

Martin Mitas 2017-01-08T09:14:49

md_process_inlines: Apply new spec rules for emph/strong emph. The spec now states that for ***foo*** we have to genarate <em><strong>foo</strong></em> instead of <strong><em>foo</em></strong>

diff --git a/md4c/md4c.c b/md4c/md4c.c
index f13149e..08a61a5 100644
--- a/md4c/md4c.c
+++ b/md4c/md4c.c
@@ -3878,21 +3878,23 @@ md_process_inlines(MD_CTX* ctx, const MD_LINE* lines, int n_lines)
                 case '_':
                 case '*':       /* Emphasis, strong emphasis. */
                     if(mark->flags & MD_MARK_OPENER) {
+                        if((mark->end - off) % 2) {
+                            MD_ENTER_SPAN(MD_SPAN_EM, NULL);
+                            off++;
+                        }
                         while(off + 1 < mark->end) {
                             MD_ENTER_SPAN(MD_SPAN_STRONG, NULL);
                             off += 2;
                         }
-                        if(off < mark->end)
-                            MD_ENTER_SPAN(MD_SPAN_EM, NULL);
                     } else {
-                        if((mark->end - off) & 0x01) {
-                            MD_LEAVE_SPAN(MD_SPAN_EM, NULL);
-                            off++;
-                        }
-                        while(off < mark->end) {
+                        while(off + 1 < mark->end) {
                             MD_LEAVE_SPAN(MD_SPAN_STRONG, NULL);
                             off += 2;
                         }
+                        if((mark->end - off) % 2) {
+                            MD_LEAVE_SPAN(MD_SPAN_EM, NULL);
+                            off++;
+                        }
                     }
                     break;