diff options
Diffstat (limited to 'layouts')
| -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 }} |
