mirror of
https://github.com/jina-ai/node-DeepResearch.git
synced 2025-12-26 06:28:56 +08:00
fix: md footnote
This commit is contained in:
parent
835d5b9a0f
commit
a3f2120885
@ -15,6 +15,9 @@ export function repairMarkdownFootnotes(
|
|||||||
// Regex to catch grouped footnotes like [^1, ^2, ^3] or [^1,^2,^3]
|
// Regex to catch grouped footnotes like [^1, ^2, ^3] or [^1,^2,^3]
|
||||||
const groupedFootnoteRegex = /\[\^(\d+)(?:,\s*\^(\d+))+]/g;
|
const groupedFootnoteRegex = /\[\^(\d+)(?:,\s*\^(\d+))+]/g;
|
||||||
|
|
||||||
|
// New regex to catch partially marked footnotes like [^10, 11]
|
||||||
|
const partialGroupedFootnoteRegex = /\[\^(\d+)(?:,\s*(\d+))+]/g;
|
||||||
|
|
||||||
// Helper function to format references
|
// Helper function to format references
|
||||||
const formatReferences = (refs: Array<Reference>) => {
|
const formatReferences = (refs: Array<Reference>) => {
|
||||||
return refs.map((ref, i) => {
|
return refs.map((ref, i) => {
|
||||||
@ -34,6 +37,11 @@ export function repairMarkdownFootnotes(
|
|||||||
// First case: no references - remove any footnote citations
|
// First case: no references - remove any footnote citations
|
||||||
if (!references?.length) {
|
if (!references?.length) {
|
||||||
return markdownString
|
return markdownString
|
||||||
|
.replace(partialGroupedFootnoteRegex, (match) => {
|
||||||
|
// Extract all numbers from the partially marked grouped footnote
|
||||||
|
const numbers = match.match(/\d+/g) || [];
|
||||||
|
return numbers.map(num => `[^${num}]`).join(', ');
|
||||||
|
})
|
||||||
.replace(groupedFootnoteRegex, (match) => {
|
.replace(groupedFootnoteRegex, (match) => {
|
||||||
// Extract all numbers from the grouped footnote
|
// Extract all numbers from the grouped footnote
|
||||||
const numbers = match.match(/\d+/g) || [];
|
const numbers = match.match(/\d+/g) || [];
|
||||||
@ -47,12 +55,16 @@ export function repairMarkdownFootnotes(
|
|||||||
.replace(/\[(\d+)\^]/g, (_, num) => `[^${num}]`)
|
.replace(/\[(\d+)\^]/g, (_, num) => `[^${num}]`)
|
||||||
.replace(/\[(\d+)]/g, (_, num) => `[^${num}]`);
|
.replace(/\[(\d+)]/g, (_, num) => `[^${num}]`);
|
||||||
|
|
||||||
// Fix grouped footnotes
|
// Fix grouped footnotes - both fully marked and partially marked types
|
||||||
processedMarkdown = processedMarkdown.replace(groupedFootnoteRegex, (match) => {
|
processedMarkdown = processedMarkdown
|
||||||
// Extract all numbers from the grouped footnote
|
.replace(groupedFootnoteRegex, (match) => {
|
||||||
const numbers = match.match(/\d+/g) || [];
|
const numbers = match.match(/\d+/g) || [];
|
||||||
return numbers.map(num => `[^${num}]`).join(', ');
|
return numbers.map(num => `[^${num}]`).join(', ');
|
||||||
});
|
})
|
||||||
|
.replace(partialGroupedFootnoteRegex, (match) => {
|
||||||
|
const numbers = match.match(/\d+/g) || [];
|
||||||
|
return numbers.map(num => `[^${num}]`).join(', ');
|
||||||
|
});
|
||||||
|
|
||||||
// Now extract all footnotes from the processed answer
|
// Now extract all footnotes from the processed answer
|
||||||
const footnotes: string[] = [];
|
const footnotes: string[] = [];
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user