Fix footnote spacing and anchor links in markdown processing

- Add spacing between consecutive footnotes
- Fix anchor href to use footnote ID
- Detect adjacent footnote patterns
- Improve footnote reference formatting
- Add non-breaking space for readability
This commit is contained in:
yangdx 2025-09-26 10:20:45 +08:00
parent fba2356c81
commit 683bbe9364

View file

@ -27,10 +27,22 @@ export const remarkFootnotes: Plugin<[], Root> = () => {
})
}
// Check if there's another footnote immediately following this one
const nextIndex = startIndex + fullMatch.length
const remainingText = text.slice(nextIndex)
const hasConsecutiveFootnote = /^\[\^[^\]]+\]/.test(remainingText)
// Add footnote reference as HTML with placeholder link
const footnoteHtml = `<sup><a href="#footnote-${id}" class="footnote-ref">${id}</a></sup>`
// Add spacing if there's a consecutive footnote
const htmlWithSpacing = hasConsecutiveFootnote
? footnoteHtml + '&nbsp;'
: footnoteHtml
replacements.push({
type: 'html',
value: `<sup><a href="#footnote" class="footnote-ref">${id}</a></sup>`
value: htmlWithSpacing
})
lastIndex = startIndex + fullMatch.length