diff options
-rw-r--r-- | src/inlines.c | 20 |
1 files changed, 17 insertions, 3 deletions
diff --git a/src/inlines.c b/src/inlines.c index 41c7140..6ed0661 100644 --- a/src/inlines.c +++ b/src/inlines.c @@ -483,6 +483,7 @@ static void process_emphasis(subject *subj, delimiter *stack_bottom) { delimiter *opener; delimiter *old_closer; bool opener_found; + bool odd_match; delimiter *openers_bottom[128]; // initialize openers_bottom: @@ -502,9 +503,18 @@ static void process_emphasis(subject *subj, delimiter *stack_bottom) { // Now look backwards for first matching opener: opener = closer->previous; opener_found = false; + odd_match = false; while (opener != NULL && opener != stack_bottom && opener != openers_bottom[closer->delim_char]) { - if (opener->delim_char == closer->delim_char && opener->can_open) { + // interior closer of size 2 can't match opener of size 1 + // or of size 1 can't match 2 + odd_match = (closer->can_open || opener->can_close) && + opener->inl_text->as.literal.len != + closer->inl_text->as.literal.len && + ((opener->inl_text->as.literal.len + + closer->inl_text->as.literal.len) % 3 == 0); + if (opener->delim_char == closer->delim_char && opener->can_open && + !odd_match) { opener_found = true; break; } @@ -534,8 +544,12 @@ static void process_emphasis(subject *subj, delimiter *stack_bottom) { } closer = closer->next; } - if (!opener_found) { - // set lower bound for future searches for openers: + if (!opener_found && !odd_match) { + // set lower bound for future searches for openers + // (we don't do this with 'odd_match' set because + // a ** that didn't match an earlier * might turn into + // an opener, and the * might be matched by something + // else. openers_bottom[old_closer->delim_char] = old_closer->previous; if (!old_closer->can_open) { // we can remove a closer that can't be an |