md_analyze_simple_pairing_mark: Fix the "rule of three". If the first emphasis opener is refused due the rule of three, a previous opener is examined. However the variable opener_orig_size_module3 was not (re)set accordingly. Fixes #21.
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 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74
diff --git a/md4c/md4c.c b/md4c/md4c.c
index 30a29cc..f41a088 100644
--- a/md4c/md4c.c
+++ b/md4c/md4c.c
@@ -3487,26 +3487,33 @@ md_analyze_simple_pairing_mark(MD_CTX* ctx, MD_MARKCHAIN* chain, int mark_index,
SZ opener_size = opener->end - opener->beg;
SZ closer_size = mark->end - mark->beg;
- if(apply_rule_of_three &&
- ((mark->flags & MD_MARK_EMPH_INTRAWORD) || (opener->flags & MD_MARK_EMPH_INTRAWORD)))
- {
- SZ opener_orig_size_modulo3;
+ /* Apply the "rule of three". */
+ if(apply_rule_of_three) {
+ while((mark->flags & MD_MARK_EMPH_INTRAWORD) || (opener->flags & MD_MARK_EMPH_INTRAWORD)) {
+ SZ opener_orig_size_modulo3;
+
+ switch(opener->flags & MD_MARK_EMPH_MODULO3_MASK) {
+ case MD_MARK_EMPH_MODULO3_0: opener_orig_size_modulo3 = 0; break;
+ case MD_MARK_EMPH_MODULO3_1: opener_orig_size_modulo3 = 1; break;
+ case MD_MARK_EMPH_MODULO3_2: opener_orig_size_modulo3 = 2; break;
+ default: MD_UNREACHABLE(); break;
+ }
- switch(opener->flags & MD_MARK_EMPH_MODULO3_MASK) {
- case MD_MARK_EMPH_MODULO3_0: opener_orig_size_modulo3 = 0; break;
- case MD_MARK_EMPH_MODULO3_1: opener_orig_size_modulo3 = 1; break;
- case MD_MARK_EMPH_MODULO3_2: opener_orig_size_modulo3 = 2; break;
- default: MD_UNREACHABLE(); break;
- }
+ if((opener_orig_size_modulo3 + closer_size) % 3 != 0) {
+ /* This opener is suitable. */
+ break;
+ }
- while((opener_orig_size_modulo3 + closer_size) % 3 == 0) {
- if(opener->prev < 0)
+ if(opener->prev >= 0) {
+ /* Try previous opener. */
+ opener_index = opener->prev;
+ opener = &ctx->marks[opener_index];
+ opener_size = opener->end - opener->beg;
+ closer_size = mark->end - mark->beg;
+ } else {
+ /* No suitable opener found. */
goto cannot_resolve;
-
- opener_index = opener->prev;
- opener = &ctx->marks[opener_index];
- opener_size = opener->end - opener->beg;
- closer_size = mark->end - mark->beg;
+ }
}
}
diff --git a/test/coverage.txt b/test/coverage.txt
index b6c868b..2a1be58 100644
--- a/test/coverage.txt
+++ b/test/coverage.txt
@@ -102,6 +102,14 @@ a***b* c*
````````````````````````````````
+### [Issue 21](https://github.com/mity/md4c/issues/21)
+```````````````````````````````` example
+a*b**c*
+.
+<p>a<em>b**c</em></p>
+````````````````````````````````
+
+
## Code coverage