md_analyze_emph: Detect correctly opener chain when resolving the range. Fixes #107.
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
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 4f99483..be70ce3 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -60,6 +60,10 @@ Fixes:
Fixed an off-by-one error in the maximal length limit of some segments
of e-mail addresses used in autolinks.
+ * [#107](https://github.com/mity/md4c/issues/107):
+ Fix mis-detection of asterisk-encoded emphasis in some corner cases when
+ length of the opener and closer differs, as in `***foo *bar baz***`.
+
## Version 0.4.2
diff --git a/md4c/md4c.c b/md4c/md4c.c
index a71ba36..b0ef739 100644
--- a/md4c/md4c.c
+++ b/md4c/md4c.c
@@ -3689,8 +3689,7 @@ md_analyze_emph(MD_CTX* ctx, int mark_index)
int i, n_opener_chains;
unsigned flags = mark->flags;
- /* Apply "rule of three". (This is why we break asterisk opener
- * marks into multiple chains.) */
+ /* Apply the "rule of three". */
n_opener_chains = 0;
opener_chains[n_opener_chains++] = &ASTERISK_OPENERS_intraword_mod3_0;
if((flags & MD_MARK_EMPH_MOD3_MASK) != MD_MARK_EMPH_MOD3_2)
@@ -3726,7 +3725,7 @@ md_analyze_emph(MD_CTX* ctx, int mark_index)
if(opener != NULL) {
SZ opener_size = opener->end - opener->beg;
SZ closer_size = mark->end - mark->beg;
- MD_MARKCHAIN* opener_chain = md_mark_chain(ctx, mark_index);
+ MD_MARKCHAIN* opener_chain = md_mark_chain(ctx, opener_index);
if(opener_size > closer_size) {
opener_index = md_split_emph_mark(ctx, opener_index, closer_size);
diff --git a/test/coverage.txt b/test/coverage.txt
index 0ff1a2f..cffdf63 100644
--- a/test/coverage.txt
+++ b/test/coverage.txt
@@ -256,6 +256,16 @@ foo
(Note the `x` here which turns it over the max. allowed length limit.)
+### [Issue 107](https://github.com/mity/md4c/issues/107)
+
+```````````````````````````````` example
+***foo *bar baz***
+.
+<p>*<strong>foo <em>bar baz</em></strong></p>
+
+````````````````````````````````
+
+
## Code coverage
### `md_is_unicode_whitespace__()`