diff --git a/lightrag_webui/src/utils/remarkFootnotes.ts b/lightrag_webui/src/utils/remarkFootnotes.ts index e90e12e4..57dd27c3 100644 --- a/lightrag_webui/src/utils/remarkFootnotes.ts +++ b/lightrag_webui/src/utils/remarkFootnotes.ts @@ -1,37 +1,11 @@ import { visit } from 'unist-util-visit' import type { Plugin } from 'unified' -import type { Root, Text, Paragraph, Html } from 'mdast' +import type { Root, Text } from 'mdast' -// Simple footnote plugin for remark +// Simple footnote plugin for remark - only renders inline citations export const remarkFootnotes: Plugin<[], Root> = () => { return (tree: Root) => { - const footnoteDefinitions = new Map() - - // First pass: collect footnote definitions and remove them - const nodesToRemove: Array<{ parent: any; index: number }> = [] - - visit(tree, 'paragraph', (node: Paragraph, index, parent) => { - if (!parent || typeof index !== 'number') return - - // Check if this paragraph contains only a footnote definition - if (node.children.length === 1 && node.children[0].type === 'text') { - const text = (node.children[0] as Text).value - const match = text.match(/^\[\^([^\]]+)\]:\s*(.+)$/) - if (match) { - const [, id, content] = match - footnoteDefinitions.set(id, content.trim()) - nodesToRemove.push({ parent, index }) - return - } - } - }) - - // Remove footnote definition paragraphs - nodesToRemove.reverse().forEach(({ parent, index }) => { - parent.children.splice(index, 1) - }) - - // Second pass: find footnote references and replace them + // Find footnote references and replace them with inline citations visit(tree, 'text', (node: Text, index, parent) => { if (!parent || typeof index !== 'number') return @@ -53,10 +27,10 @@ export const remarkFootnotes: Plugin<[], Root> = () => { }) } - // Add footnote reference as HTML + // Add footnote reference as HTML with placeholder link replacements.push({ type: 'html', - value: `${id}` + value: `${id}` }) lastIndex = startIndex + fullMatch.length @@ -75,42 +49,5 @@ export const remarkFootnotes: Plugin<[], Root> = () => { parent.children.splice(index, 1, ...replacements) } }) - - // Third pass: add footnotes section at the end if we have definitions - if (footnoteDefinitions.size > 0) { - const footnotesList: any[] = [] - - footnoteDefinitions.forEach((content, id) => { - footnotesList.push({ - type: 'listItem', - children: [{ - type: 'paragraph', - children: [{ - type: 'html', - value: `${content} ` - }] - }] - }) - }) - - // Add footnotes section - tree.children.push({ - type: 'html', - value: '
' - } as Html) - - tree.children.push({ - type: 'list', - ordered: true, - start: 1, - spread: false, - children: footnotesList - }) - - tree.children.push({ - type: 'html', - value: '
' - } as Html) - } } }