summaryrefslogtreecommitdiff
path: root/layouts/_partials/utils/inject-footnotes.html
diff options
context:
space:
mode:
authoreltrac <hi@eltr.ac>2026-04-07 14:53:17 +0800
committereltrac <hi@eltr.ac>2026-04-07 14:53:17 +0800
commit10431bd8f5ff71690ae4e5444e8d7894fd401ae5 (patch)
tree62b7fd1b6c1f68d2804f380eb522bcebeb2c8d9f /layouts/_partials/utils/inject-footnotes.html
parent3e0edacc4a0cafa53ede57ebb6f0378c93f3123b (diff)
chore: move templates out of site repo
Diffstat (limited to 'layouts/_partials/utils/inject-footnotes.html')
-rw-r--r--layouts/_partials/utils/inject-footnotes.html70
1 files changed, 0 insertions, 70 deletions
diff --git a/layouts/_partials/utils/inject-footnotes.html b/layouts/_partials/utils/inject-footnotes.html
deleted file mode 100644
index 31fdae82..00000000
--- a/layouts/_partials/utils/inject-footnotes.html
+++ /dev/null
@@ -1,70 +0,0 @@
-{{ $content := . }}
-
-{{ $footnotesPattern := `(?s)<div class="footnotes"[^>]*>.*?</div>` }}
-{{ $footnotesMatch := findRE $footnotesPattern $content 1 }}
-
-{{ if $footnotesMatch }}
- {{ $footnotesSection := index $footnotesMatch 0 }}
-
- {{ $liPattern := `(?s)<li id="fn:(\d+)">(.*?)</li>` }}
- {{ $footnoteItems := findRESubmatch $liPattern $footnotesSection }}
-
- {{ $footnoteMap := dict }}
- {{ range $footnoteItems }}
- {{ $id := index . 1 }}
- {{ $contentRaw := index . 2 }}
- {{ $cleanContent := replaceRE `(?s)\s*<a href="#fnref:\d+"[^>]*>.*?</a>\s*$` "" $contentRaw }}
- {{ $footnoteMap = merge $footnoteMap (dict $id $cleanContent) }}
- {{ end }}
-
- {{ $contentWithoutFootnotes := replaceRE $footnotesPattern "" $content }}
-
- {{ $refPattern := `<sup id="fnref:(\d+)".*?</sup>` }}
- {{ $refs := findRESubmatch $refPattern $contentWithoutFootnotes }}
-
- {{ $result := $contentWithoutFootnotes }}
- {{ $count := len $refs }}
-
- {{ range seq (sub $count 1) -1 0 }}
- {{ $ref := index $refs . }}
- {{ $refFull := index $ref 0 }}
- {{ $refId := index $ref 1 }}
- {{ $noteContent := index $footnoteMap $refId }}
-
- {{ if $noteContent }}
- {{ $inlineFootnote := printf `<div class="inline-footnote text-xs text-secondary flex gap-2 ml-2 my-1 opacity-50 hover:opacity-100 transition-opacity" id="fn:%s"><span>%s.</span><div>%s</div></div>` $refId $refId $noteContent }}
-
- {{ $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 }}
-
- {{ $content = $result }}
-{{ end }}
-
-{{ $content | safeHTML }}