md_collect_marks: Minor refactorization of emhasis handler.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56
diff --git a/md4c/md4c.c b/md4c/md4c.c
index e0f5ffe..30a29cc 100644
--- a/md4c/md4c.c
+++ b/md4c/md4c.c
@@ -2754,7 +2754,6 @@ md_collect_marks(MD_CTX* ctx, const MD_LINE* lines, int n_lines, int table_mode)
OFF tmp = off+1;
int left_level; /* What precedes: 0 = whitespace; 1 = punctuation; 2 = other char. */
int right_level; /* What follows: 0 = whitespace; 1 = punctuation; 2 = other char. */
- unsigned flags = 0;
while(tmp < line_end && CH(tmp) == ch)
tmp++;
@@ -2779,24 +2778,26 @@ md_collect_marks(MD_CTX* ctx, const MD_LINE* lines, int n_lines, int table_mode)
right_level = 0;
}
- if(left_level > 0 && left_level >= right_level)
- flags |= MD_MARK_POTENTIAL_CLOSER;
- if(right_level > 0 && right_level >= left_level)
- flags |= MD_MARK_POTENTIAL_OPENER;
- if(left_level == 2 && right_level == 2)
- flags |= MD_MARK_EMPH_INTRAWORD;
-
- /* For "the rule of three" we need to remember the original
- * size of the mark (modulo three), before we potentially
- * split the mark when being later resolved partially by some
- * shorter closer. */
- switch((tmp - off) % 3) {
- case 0: flags |= MD_MARK_EMPH_MODULO3_0; break;
- case 1: flags |= MD_MARK_EMPH_MODULO3_1; break;
- case 2: flags |= MD_MARK_EMPH_MODULO3_2; break;
- }
+ if(left_level != 0 || right_level != 0) {
+ unsigned flags = 0;
+
+ if(left_level > 0 && left_level >= right_level)
+ flags |= MD_MARK_POTENTIAL_CLOSER;
+ if(right_level > 0 && right_level >= left_level)
+ flags |= MD_MARK_POTENTIAL_OPENER;
+ if(left_level == 2 && right_level == 2)
+ flags |= MD_MARK_EMPH_INTRAWORD;
+
+ /* For "the rule of three" we need to remember the original
+ * size of the mark (modulo three), before we potentially
+ * split the mark when being later resolved partially by some
+ * shorter closer. */
+ switch((tmp - off) % 3) {
+ case 0: flags |= MD_MARK_EMPH_MODULO3_0; break;
+ case 1: flags |= MD_MARK_EMPH_MODULO3_1; break;
+ case 2: flags |= MD_MARK_EMPH_MODULO3_2; break;
+ }
- if(flags != 0) {
PUSH_MARK(ch, off, tmp, flags);
/* During resolving, multiple asterisks may have to be