From: Fletcher T. Penney Date: Tue, 14 Mar 2017 22:44:54 +0000 (-0400) Subject: FIXED: Fix edge case with superscripts X-Git-Tag: 6.0.0-rc1^2~14 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=eafc70407b8dacfa77062bbb90a8bdcbc5cba012;p=multimarkdown FIXED: Fix edge case with superscripts --- diff --git a/Sources/libMultiMarkdown/mmd.c b/Sources/libMultiMarkdown/mmd.c index 35a6184..295dd58 100644 --- a/Sources/libMultiMarkdown/mmd.c +++ b/Sources/libMultiMarkdown/mmd.c @@ -1316,12 +1316,17 @@ void mmd_assign_ambidextrous_tokens_in_block(mmd_engine * e, token * block, cons t->can_close = 0; // Shift next token right and move those characters as child node - if ((t->next != NULL) && ((t->next->type == TEXT_PLAIN) || (t->next->type == TEXT_NUMBER_POSS_LIST))) { - t->next->start += t->len - 1; - t->next->len -= t->len - 1; + // It's possible that one (or more?) tokens are entirely subsumed. + while (t->next && t->next->start + t->next->len < offset) { + tokens_prune(t->next, t->next); + } - t->child = token_new(TEXT_PLAIN, t->start + 1, t->len - 1); + if ((t->next != NULL) && ((t->next->type == TEXT_PLAIN) || (t->next->type == TEXT_NUMBER_POSS_LIST))) { + t->next->len = t->next->start + t->next->len - offset; + t->next->start = offset; } + + t->child = token_new(TEXT_PLAIN, t->start + 1, t->len - 1); } }