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:
parent
fba2356c81
commit
683bbe9364
1 changed files with 13 additions and 1 deletions
|
|
@ -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
|
// 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 + ' '
|
||||||
|
: footnoteHtml
|
||||||
|
|
||||||
replacements.push({
|
replacements.push({
|
||||||
type: 'html',
|
type: 'html',
|
||||||
value: `<sup><a href="#footnote" class="footnote-ref">${id}</a></sup>`
|
value: htmlWithSpacing
|
||||||
})
|
})
|
||||||
|
|
||||||
lastIndex = startIndex + fullMatch.length
|
lastIndex = startIndex + fullMatch.length
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue