2022-04-25 15:49:13 +00:00
|
|
|
{{- $footnote_heading := printf "Footnotes" -}}
|
|
|
|
{{- if .Params.footnote_heading -}}
|
|
|
|
{{- $footnote_heading = .Params.footnote_heading -}}
|
|
|
|
{{- end -}}
|
2022-04-06 04:41:08 +00:00
|
|
|
|
2022-04-25 15:49:13 +00:00
|
|
|
<!--
|
|
|
|
Add heading to footnotes, remove unused class.
|
|
|
|
Requires Goldmark v1.4.12 or higher, since that version switched
|
|
|
|
endnotes from a <section> to a <div>.
|
|
|
|
-->
|
|
|
|
{{- $referencesWithoutHeading := `(<div class="footnotes" role="doc-endnotes">
|
2021-01-18 03:42:07 +00:00
|
|
|
<hr>)` -}}
|
2022-05-04 04:30:20 +00:00
|
|
|
{{- $referencesWithHeading := printf `<section role="doc-endnotes" aria-labelledby="note-hd">
|
2022-04-18 15:59:43 +00:00
|
|
|
<h2 id="note-hd">%s</h2>` ($footnote_heading) -}}
|
2022-04-06 04:41:08 +00:00
|
|
|
|
2022-05-04 04:30:20 +00:00
|
|
|
{{- $endnotesClosingDiv := `</a></p>
|
|
|
|
</li>
|
|
|
|
</ol>
|
|
|
|
</div>` -}}
|
|
|
|
|
|
|
|
{{- $endnotesClosingSection := printf `</a></p>
|
|
|
|
</li>
|
|
|
|
</ol>
|
|
|
|
</section>` -}}
|
|
|
|
|
2022-04-09 15:54:58 +00:00
|
|
|
<!--Remove deprecated DPUB-ARIA role and unused classes-->
|
2022-04-25 15:49:13 +00:00
|
|
|
{{- $endnote := `(role="doc-endnote"|class="footnote-(back)?ref")` -}}
|
|
|
|
{{- $noEndnote := printf "" -}}
|
2022-04-07 00:49:25 +00:00
|
|
|
|
2022-04-09 15:51:10 +00:00
|
|
|
<!--Move the Table of Contents heading *inside* the <nav> element-->
|
2022-04-25 15:49:13 +00:00
|
|
|
{{- $tocHeadingOutside := `<h2>Table of Contents</h2><nav(?:.*)>` -}}
|
|
|
|
{{- $tocHeadingInside := `<nav id=TableOfContents role="doc-toc"><h2 id="toc-hd">Table of Contents</h2>` -}}
|
2022-04-09 15:51:10 +00:00
|
|
|
|
2022-04-18 15:59:43 +00:00
|
|
|
<!--Give footnote backlinks accessible names-->
|
2022-04-25 15:49:13 +00:00
|
|
|
{{- $footnoteBacklinksBad := `<a href="#fnref:([0-9]*)"(.*role="doc-backlink"(?:.*)?)>` -}}
|
|
|
|
{{- $footnoteBacklinksGood := `<a href="#fnref:${1}" title="back to reference ${1}" aria-label="back to reference ${1}"${2}>` -}}
|
2022-04-18 15:59:43 +00:00
|
|
|
|
2022-04-29 00:41:13 +00:00
|
|
|
{{- $repeatedFootnoteBacklinksBad := `<a href="#fnref([0-9]):([0-9]*)"(.*role="doc-backlink"(?:.*)?)>` -}}
|
|
|
|
{{- $repeatedFootnoteBacklinksGood := `<a href="#fnref${1}:${2}" title="back to reference ${2}, repeated instance ${1}" aria-label="back to reference ${2}, repeated instance ${1}"${3}>` -}}
|
|
|
|
|
2022-05-04 04:30:20 +00:00
|
|
|
{{- .Content | replaceRE $referencesWithoutHeading $referencesWithHeading | replaceRE $endnotesClosingDiv $endnotesClosingSection | replaceRE $endnote $noEndnote | replaceRE $tocHeadingOutside $tocHeadingInside | replaceRE $footnoteBacklinksBad $footnoteBacklinksGood | replaceRE $repeatedFootnoteBacklinksBad $repeatedFootnoteBacklinksGood | safeHTML -}}
|