mirror of
https://git.sr.ht/~seirdy/seirdy.one
synced 2024-12-25 02:02:11 +00:00
1aed7a66d4
The site now has polygot markup and can handle both XHTML5 and HTML5 parsing rules. My staging site will be XHTML but my main site will be HTML5, just in case of parse errors. If other tools (e.g. LightHouse) end up supporting XHTML5, I'll consider switching the content-type to XHTML.
53 lines
2.9 KiB
HTML
53 lines
2.9 KiB
HTML
{{- $footnote_heading := printf "Footnotes" -}}
|
||
{{- if .Params.footnote_heading -}}
|
||
{{- $footnote_heading = .Params.footnote_heading -}}
|
||
{{- end -}}
|
||
|
||
<!--
|
||
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">
|
||
<hr />)` -}}
|
||
{{- $referencesWithHeading := printf `<section role="doc-endnotes" aria-labelledby="note-hd">
|
||
<h2 id="note-hd">%s</h2>` ($footnote_heading) -}}
|
||
|
||
{{- $endnotesClosingDiv := `</a></p>
|
||
</li>
|
||
</ol>
|
||
</div>` -}}
|
||
|
||
{{- $endnotesClosingSection := printf `</a></p>
|
||
</li>
|
||
</ol>
|
||
</section>` -}}
|
||
|
||
<!--
|
||
Descriptive footnote link names, remove unused class, put
|
||
backlink id in <a> since <a> is focusable, remove unused class.
|
||
-->
|
||
{{- $badNoteRef := `<sup id="fnref([0-9\:]*)"><a( [^>]*)class="footnote-ref" role="doc-noteref">([0-9]*)</a>` -}}
|
||
{{- $goodNoteRef := `<sup><a${2}id="fnref${1}" role="doc-noteref">note ${3}</a>` -}}
|
||
|
||
<!--Move the Table of Contents heading *inside* the <nav> element-->
|
||
{{- $tocHeadingOutside := `<h2>Table of Contents</h2><nav(?:.*)>` -}}
|
||
{{- $tocHeadingInside := `<nav id="TableOfContents" role="doc-toc" aria-labelledby="toc-hd" tabindex="-1">
|
||
<h2 id="toc-hd">Table of Contents</h2>` -}}
|
||
|
||
<!--Give footnote backlinks accessible names-->
|
||
{{- $footnoteBacklinksBad := `<a href="#fnref:([0-9]*)" class="footnote-backref"(.*role="doc-backlink"(?:[^>]*)?)>([^<]*)` -}}
|
||
{{- $footnoteBacklinksGood := `<a href="#fnref:${1}" aria-labelledby="bl-${1}"${2}>${3} <span id="bl-${1}" hidden="">back to reference ${1}</span>` -}}
|
||
|
||
<!--
|
||
If two backlinks exist, give them different names.
|
||
I currently don't have any triple backlinks; if I ever do, I'll implement this properly with a loop.
|
||
-->
|
||
{{- $repeatedFootnoteBacklinksBad := `<a href="#fnref([0-9]):([0-9]*)"(.*role="doc-backlink"(?:[^>]*)?)>([^<]*)` -}}
|
||
{{- $repeatedFootnoteBacklinksGood := `<a href="#fnref${1}:${2}" aria-labelledby="bl-${2}-2"${3}>${4} <span id="bl-${2}-2" hidden="">back to reference ${2}, instance 2</span>` -}}
|
||
|
||
<!--Make endnotes focusable by ATs. Necessary for VoiceOver compatibility.-->
|
||
{{- $endNotesNotFocusable := `<li id="fn:([0-9]*)">` -}}
|
||
{{- $endNotesFocusable := `<li id="fn:${1}" tabindex="-1">` -}}
|
||
|
||
{{- .Content | replaceRE $referencesWithoutHeading $referencesWithHeading | replaceRE $badNoteRef $goodNoteRef | replaceRE $endnotesClosingDiv $endnotesClosingSection | replaceRE $tocHeadingOutside $tocHeadingInside | replaceRE $footnoteBacklinksBad $footnoteBacklinksGood | replaceRE $repeatedFootnoteBacklinksBad $repeatedFootnoteBacklinksGood | replaceRE $endNotesNotFocusable $endNotesFocusable | replaceRE `\’` `’` | replaceRE `\ ` `\ ` | replaceRE `\“` `“` | replaceRE `\”` `”` | replaceRE `\…` `—` | replaceRE `\—` `—` | replaceRE `\­` `\­` | replaceRE `‘` `‘`| safeHTML -}}
|