From eafc70407b8dacfa77062bbb90a8bdcbc5cba012 Mon Sep 17 00:00:00 2001 From: "Fletcher T. Penney" Date: Tue, 14 Mar 2017 18:44:54 -0400 Subject: [PATCH] FIXED: Fix edge case with superscripts --- Sources/libMultiMarkdown/mmd.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) 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); } } -- 2.40.0