mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-04 09:30:22 +00:00
fix(markdown): require paired || delimiters for spoiler detection (#26105)
* fix(markdown): require paired || delimiters for spoiler detection An unpaired || (odd count across all inline tokens) would open a spoiler that never closes, causing closeRemainingStyles to extend it to the end of the text. This made all content after an unpaired || appear as hidden/spoiler in Telegram. Pre-count || delimiters across the entire inline token group and skip spoiler injection entirely when the count is less than 2 or odd. This prevents single | characters and unpaired || from triggering spoiler formatting. Closes #26068 Co-authored-by: Cursor <cursoragent@cursor.com> * fix: preserve valid spoiler pairs with trailing unmatched delimiters (#26105) (thanks @Sid-Qin) --------- Co-authored-by: Cursor <cursoragent@cursor.com> Co-authored-by: Peter Steinberger <steipete@gmail.com>
This commit is contained in:
@@ -144,8 +144,31 @@ function applySpoilerTokens(tokens: MarkdownToken[]): void {
|
||||
}
|
||||
|
||||
function injectSpoilersIntoInline(tokens: MarkdownToken[]): MarkdownToken[] {
|
||||
let totalDelims = 0;
|
||||
for (const token of tokens) {
|
||||
if (token.type !== "text") {
|
||||
continue;
|
||||
}
|
||||
const content = token.content ?? "";
|
||||
let i = 0;
|
||||
while (i < content.length) {
|
||||
const next = content.indexOf("||", i);
|
||||
if (next === -1) {
|
||||
break;
|
||||
}
|
||||
totalDelims += 1;
|
||||
i = next + 2;
|
||||
}
|
||||
}
|
||||
|
||||
if (totalDelims < 2) {
|
||||
return tokens;
|
||||
}
|
||||
const usableDelims = totalDelims - (totalDelims % 2);
|
||||
|
||||
const result: MarkdownToken[] = [];
|
||||
const state = { spoilerOpen: false };
|
||||
let consumedDelims = 0;
|
||||
|
||||
for (const token of tokens) {
|
||||
if (token.type !== "text") {
|
||||
@@ -168,9 +191,14 @@ function injectSpoilersIntoInline(tokens: MarkdownToken[]): MarkdownToken[] {
|
||||
}
|
||||
break;
|
||||
}
|
||||
if (consumedDelims >= usableDelims) {
|
||||
result.push(createTextToken(token, content.slice(index)));
|
||||
break;
|
||||
}
|
||||
if (next > index) {
|
||||
result.push(createTextToken(token, content.slice(index, next)));
|
||||
}
|
||||
consumedDelims += 1;
|
||||
state.spoilerOpen = !state.spoilerOpen;
|
||||
result.push({
|
||||
type: state.spoilerOpen ? "spoiler_open" : "spoiler_close",
|
||||
|
||||
Reference in New Issue
Block a user