diff --git a/packages/app/src/components/markdown/html.ts b/packages/app/src/components/markdown/html.ts index 464c65d729..1cde4dad46 100644 --- a/packages/app/src/components/markdown/html.ts +++ b/packages/app/src/components/markdown/html.ts @@ -14,6 +14,13 @@ const EMPHASIS: Readonly> = { b: "**", strong: "**", i: " /** Convert comment HTML to Markdown while preserving the original spelling of code. */ export function normalizeMarkdownHtml(source: string): string { if (!source.includes("<")) return source; + const htmlRanges: { start: number; end: number }[] = []; + function findHtml(node: Nodes) { + if (node.type === "html" && node.position) { + htmlRanges.push({ start: node.position.start.offset!, end: node.position.end.offset! }); + } else if ("children" in node) node.children.forEach(findHtml); + } + findHtml(fromMarkdown(source)); const codeRanges: { start: number; end: number }[] = []; // Disable HTML parsing so code inside
remains visible to the Markdown parser. const tree = fromMarkdown(source, { @@ -28,7 +35,7 @@ export function normalizeMarkdownHtml(source: string): string { } protectCode(tree); const links: (string | undefined)[] = []; - return source.replace(HTML, (raw: string, offset: number) => { + const convert = (raw: string, offset: number): string => { if (codeRanges.some(({ start, end }) => offset >= start && offset < end)) return raw; if (raw.startsWith("