From d748febafce311e451dbc1433de730097a52e5f0 Mon Sep 17 00:00:00 2001 From: Han Xiao Date: Thu, 20 Mar 2025 15:08:14 +0800 Subject: [PATCH] fix: md table render --- src/utils/text-tools.ts | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/src/utils/text-tools.ts b/src/utils/text-tools.ts index 8b31f4b..fd8f489 100644 --- a/src/utils/text-tools.ts +++ b/src/utils/text-tools.ts @@ -1,6 +1,6 @@ import {AnswerAction, KnowledgeItem, Reference} from "../types"; import i18nJSON from './i18n.json'; -import { JSDOM } from 'jsdom'; +import {JSDOM} from 'jsdom'; export function buildMdFromAnswer(answer: AnswerAction) { @@ -166,11 +166,11 @@ export function repairMarkdownFootnotesOuter(markdownString: string): string { // 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```$/; +// Check if the string starts with ```markdown or ```html and ends with ``` + const codeBlockRegex = /^```(markdown|html)\n([\s\S]*)\n```$/; const codeBlockMatch = markdownString.match(codeBlockRegex); if (codeBlockMatch) { - markdownString = codeBlockMatch[1]; + markdownString = codeBlockMatch[2]; } // Extract existing footnote definitions @@ -432,7 +432,6 @@ ${k.answer} } - /** * Converts HTML tables in a markdown string to markdown tables * @param mdString The markdown string containing potential HTML tables @@ -636,12 +635,10 @@ function sanitizeCell(content: string): string { } - - if (typeof window === 'undefined') { global.DOMParser = class DOMParser { parseFromString(htmlString: string, mimeType: string) { - const dom = new JSDOM(htmlString, { contentType: mimeType }); + const dom = new JSDOM(htmlString, {contentType: mimeType}); return dom.window.document; } };