md_analyze_emph: Call md_resolve_range() with proper chain. Errorneously, we have called md_resolve_range() with mark chain derived from the closer mark. In the case that the opener and closer marks differ in length (and we have split one or the other), we pass in an incorrect chain, which may lead to strange behavior in subsequent analysis. Fixes #98.
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
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 0f1b46d..e11376f 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -2,6 +2,14 @@
# MD4C Change Log
+## Next Version (Work in Progress)
+
+Fixes:
+ * [#98](https://github.com/mity/md4c/issues/98):
+ Fix mis-detection of asterisk-encoded emphasis in some corner cases when
+ length of the opener and closer differs, as in `**a *b c** d*`.
+
+
## Version 0.4.1
Unfortunately, 0.4.0 has been released with badly updated ChangeLog. Fixing
diff --git a/md4c/md4c.c b/md4c/md4c.c
index 27164b9..5692adf 100644
--- a/md4c/md4c.c
+++ b/md4c/md4c.c
@@ -3699,16 +3699,17 @@ 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);
if(opener_size > closer_size) {
opener_index = md_split_emph_mark(ctx, opener_index, closer_size);
- md_mark_chain_append(ctx, md_mark_chain(ctx, opener_index), opener_index);
+ md_mark_chain_append(ctx, opener_chain, opener_index);
} else if(opener_size < closer_size) {
md_split_emph_mark(ctx, mark_index, closer_size - opener_size);
}
md_rollback(ctx, opener_index, mark_index, MD_ROLLBACK_CROSSING);
- md_resolve_range(ctx, chain, opener_index, mark_index);
+ md_resolve_range(ctx, opener_chain, opener_index, mark_index);
return;
}
}
diff --git a/test/coverage.txt b/test/coverage.txt
index 24a99da..7847736 100644
--- a/test/coverage.txt
+++ b/test/coverage.txt
@@ -230,6 +230,17 @@ foo
````````````````````````````````
+### [Issue 97](https://github.com/mity/md4c/issues/97)
+
+
+```````````````````````````````` example
+*a **b c* d**
+.
+<p><em>a <em><em>b c</em> d</em></em></p>
+
+````````````````````````````````
+
+
## Code coverage
### `md_is_unicode_whitespace__()`