Skip to content

Commit

Permalink
md_analyze_emph: Call md_resolve_range() with proper chain.
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
mity committed Nov 12, 2019
1 parent 7876421 commit 46f25f0
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 2 deletions.
8 changes: 8 additions & 0 deletions CHANGELOG.md
Expand Up @@ -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
Expand Down
5 changes: 3 additions & 2 deletions md4c/md4c.c
Expand Up @@ -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;
}
}
Expand Down
11 changes: 11 additions & 0 deletions test/coverage.txt
Expand Up @@ -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__()`
Expand Down

0 comments on commit 46f25f0

Please sign in to comment.