fix: md ref

This commit is contained in:
Han Xiao 2025-04-14 12:19:45 +08:00
parent 1f9565ec84
commit 098564eb81
2 changed files with 30 additions and 12 deletions

View File

@ -996,7 +996,7 @@ But unfortunately, you failed to solve the issue. You need to think out of the b
answerStep.answer = answer; answerStep.answer = answer;
answerStep.references = references; answerStep.references = references;
await updateReferences(answerStep, allURLs) await updateReferences(answerStep, allURLs)
answerStep.mdAnswer = buildMdFromAnswer(answerStep); answerStep.mdAnswer = repairMarkdownFootnotesOuter(buildMdFromAnswer(answerStep));
} else { } else {
answerStep.mdAnswer = answerStep.mdAnswer =
convertHtmlTablesToMd( convertHtmlTablesToMd(

View File

@ -232,7 +232,24 @@ export async function buildReferences(
// Calculate position to insert the marker (end of the chunk + current offset) // Calculate position to insert the marker (end of the chunk + current offset)
let insertPosition = ref.answerChunkPosition![1] + offset; let insertPosition = ref.answerChunkPosition![1] + offset;
// Check if there's a newline or table pipe at the end of the chunk and adjust position // Look ahead to check if there's a list item coming next
const textAfterInsert = modifiedAnswer.substring(insertPosition);
const nextListItemMatch = textAfterInsert.match(/^\s*\n\s*\*/);
// If we're at a position where the next content is a list item,
// we need to adjust WHERE we place the footnote
if (nextListItemMatch) {
// Move the marker to right after the last content character,
// but INSIDE any punctuation at the end of the content
const beforeText = modifiedAnswer.substring(Math.max(0, insertPosition - 30), insertPosition);
const lastPunctuation = beforeText.match(/[!。?!.?]$/);
if (lastPunctuation) {
// If there's punctuation at the end, insert the marker before it
insertPosition--;
}
} else {
// The original conditions for newlines and table pipes can remain
const chunkEndText = modifiedAnswer.substring(Math.max(0, insertPosition - 5), insertPosition); const chunkEndText = modifiedAnswer.substring(Math.max(0, insertPosition - 5), insertPosition);
const newlineMatch = chunkEndText.match(/\n+$/); const newlineMatch = chunkEndText.match(/\n+$/);
const tableEndMatch = chunkEndText.match(/\s*\|\s*$/); const tableEndMatch = chunkEndText.match(/\s*\|\s*$/);
@ -244,6 +261,7 @@ export async function buildReferences(
// Move the insertion position before the table end pipe // Move the insertion position before the table end pipe
insertPosition -= tableEndMatch[0].length; insertPosition -= tableEndMatch[0].length;
} }
}
// Insert the marker // Insert the marker
modifiedAnswer = modifiedAnswer =