diff options
| author | eltrac <hi@eltr.ac> | 2026-02-10 14:23:29 +0800 |
|---|---|---|
| committer | eltrac <hi@eltr.ac> | 2026-02-10 14:23:29 +0800 |
| commit | 3641dc9bb9c2db36d93c677dc9136df3f3b77c7d (patch) | |
| tree | d5fda0fcd93d59f92aaca3650ff3d93fce44191d | |
| parent | 1b844f1230a03983bf027a321eb77bb908f469ea (diff) | |
fix(render): injected footnotes interrupt paragraph
| -rw-r--r-- | layouts/_partials/utils/inject-footnotes.html | 30 |
1 files changed, 28 insertions, 2 deletions
diff --git a/layouts/_partials/utils/inject-footnotes.html b/layouts/_partials/utils/inject-footnotes.html index 57cc1e00..d95d668b 100644 --- a/layouts/_partials/utils/inject-footnotes.html +++ b/layouts/_partials/utils/inject-footnotes.html @@ -33,8 +33,34 @@ {{ if $noteContent }} {{ $inlineFootnote := printf `<div class="inline-footnote text-sm text-secondary flex gap-2 ml-4 mt-2 mb-2" id="fn:%s"><span>%s.</span><div>%s</div></div>` $refId $refId $noteContent }} - {{ $replacement := printf `%s%s` $refFull $inlineFootnote }} - {{ $result = replace $result $refFull $replacement 1 }} + + {{ $blockTags := slice "p" "li" "td" "th" "blockquote" "h1" "h2" "h3" "h4" "h5" "h6" "figcaption" "dt" "dd" }} + + {{ $found := false }} + + {{ range $blockTags }} + {{ if not $found }} + {{ $tag := . }} + {{ $pattern := printf `(?s)<%s[^>]*>.*?</%s>` $tag $tag }} + {{ $matches := findRE $pattern $result }} + + {{ range $matches }} + {{ if not $found }} + {{ $block := . }} + {{ if strings.Contains $block $refFull }} + {{ $newBlock := printf `%s%s` $block $inlineFootnote }} + {{ $result = replace $result $block $newBlock 1 }} + {{ $found = true }} + {{ end }} + {{ end }} + {{ end }} + {{ end }} + {{ end }} + + {{ if not $found }} + {{ $replacement := printf `%s%s` $refFull $inlineFootnote }} + {{ $result = replace $result $refFull $replacement 1 }} + {{ end }} {{ end }} {{ end }} |
