From 7d77efe0f1cfa4782893ffde78419a96a95240f4 Mon Sep 17 00:00:00 2001 From: Timothy Jaeryang Baek Date: Mon, 27 Jul 2026 02:47:09 -0400 Subject: [PATCH] refac --- src/lib/utils/marked/extension.ts | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/src/lib/utils/marked/extension.ts b/src/lib/utils/marked/extension.ts index 13f9f7cdc3..86939c9151 100644 --- a/src/lib/utils/marked/extension.ts +++ b/src/lib/utils/marked/extension.ts @@ -63,6 +63,21 @@ function detailsStart(src: string) { return src.match(/^]/) ? 0 : -1; } +function lheadingTokenizer(this: any, src: string): any { + const cap = this.rules.block.lheading.exec(src); + const detailsIndex = cap?.[1]?.search(/\n]/) ?? -1; + if (!cap || detailsIndex === -1) return false; + + const raw = cap[1].slice(0, detailsIndex + 1); + const text = raw.slice(0, -1); + return { + type: 'paragraph', + raw, + text, + tokens: this.lexer.inline(text) + }; +} + function detailsRenderer(token: any) { const attributesString = token.attributes ? Object.entries(token.attributes) @@ -89,6 +104,9 @@ function detailsExtension() { export default function (options = {}) { return { - extensions: [detailsExtension(options)] + tokenizer: { + lheading: lheadingTokenizer as any + }, + extensions: [detailsExtension()] }; }