From f1c552ea32062dd70861ad0292d54e2888c7d891 Mon Sep 17 00:00:00 2001 From: yuxi-liu-wired <33951560+yuxi-liu-wired@users.noreply.github.com> Date: Sun, 4 Oct 2026 21:36:56 +0000 Subject: [PATCH] Keep the last closer position in the backtick cache scan_to_closing_backticks records, for each backtick-string length, the position of the last such string it saw, so a later opener can tell there is no closer without rescanning. A scan that starts after an earlier one had already reached the end of the input overwrote a later position with an earlier one. A following opener of that length then saw a closer position before itself and gave up: ``x `i` `j` rendered `` `j` `` as text instead of a code span. Store a position only if it is past the one already recorded. --- src/inlines.c | 6 ++++-- test/regression.txt | 13 +++++++++++++ 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/src/inlines.c b/src/inlines.c index bf765eab5..abaeb96e1 100644 --- a/src/inlines.c +++ b/src/inlines.c @@ -342,8 +342,10 @@ static bufsize_t scan_to_closing_backticks(subject *subj, advance(subj); numticks++; } - // store position of ender - if (numticks <= MAXBACKTICKS) { + // store position of ender (keep the last one: a scan that resumes after + // an earlier full scan must not replace a later position) + if (numticks <= MAXBACKTICKS && + subj->backticks[numticks] < subj->pos - numticks) { subj->backticks[numticks] = subj->pos - numticks; } if (numticks == openticklength) { diff --git a/test/regression.txt b/test/regression.txt index 1426617ab..6456ccbf8 100644 --- a/test/regression.txt +++ b/test/regression.txt @@ -257,6 +257,19 @@ x <- 1 ```````````````````````````````` +Code spans after an unmatched backtick string of a different length. +The failed scan for the closer of ``` `` ``` must not hide the second +single-backtick span. +```````````````````````````````` example +``x +`i` +`j` +. +
``x
+i
+j