From 63999ba739672a323e8a4f52547799960764d53f Mon Sep 17 00:00:00 2001 From: Han Xiao Date: Wed, 19 Mar 2025 18:46:41 +0800 Subject: [PATCH] fix: md footnote --- src/utils/text-tools.ts | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/utils/text-tools.ts b/src/utils/text-tools.ts index 87e00b1..46f7fcb 100644 --- a/src/utils/text-tools.ts +++ b/src/utils/text-tools.ts @@ -160,6 +160,17 @@ ${formatReferences(references)} * It extracts existing footnote definitions and uses them as references */ export function repairMarkdownFootnotesSimple(markdownString: string): string { + // Remove outer code fence if it exists + // First trim the string to handle any extra whitespace + markdownString = markdownString.trim(); + + // Check if the string starts with ```markdown and ends with ``` + const codeBlockRegex = /^```markdown\n([\s\S]*)\n```$/; + const codeBlockMatch = markdownString.match(codeBlockRegex); + if (codeBlockMatch) { + markdownString = codeBlockMatch[1]; + } + // Extract existing footnote definitions const footnoteDefRegex = /\[\^(\d+)]:\s*(.*?)(?=\n\[\^|$)/gs; const references: Array = [];