My situation is a bit complex, I need to append a markdown generated footnotes section with a bit more html than what is being generated; essentially adding a heading and a button (and probably some ARIA
attributes, but I’m not there yet. I am already doing a bit of complicated find and replace in the first partial, and am needing to do another on the same page but via a separate partial Here’s my approach:
in single.html:
{{ $para := partial "first-paragraph.html" .Content }}
{{ $notes := partial "footnotes.html" $para }}
{{ $notes }}
In first-paragraph.html
we have:
{{- $content := . -}}
{{ $stringToFind := `^<p>\S+`}}
{{- with findRE $stringToFind $content -}}
{{- $firstWord := index . 0 | strings.TrimPrefix "<p>" -}}
{{- $firstCharacter := substr $firstWord 0 1 -}}
{{- $remainingCharacters := substr $firstWord 1 -}}
{{- $chunk := `
<p class="[ has-dropcap ]">
<span aria-hidden="true">
<span class="[ dropcap ]">firstCharacter</span>remainingCharacters
</span>
<span class="[ sr-only ]">firstWord</span>` -}}
{{- $chunk = replace $chunk "firstCharacter" $firstCharacter -}}
{{- $chunk = replace $chunk "remainingCharacters" $remainingCharacters -}}
{{- $chunk = replace $chunk "firstWord" $firstWord -}}
{{- replaceRE `^<p>\S+` $chunk $content | safeHTML -}}
{{- else -}}
{{- $content | safeHTML -}}
{{- end -}}
and in footnotes.html
:
{{ $content := . }}
{{ $stringToFind := `<section class="footnotes" role="doc-endnotes">` }}
{{- $append := `
<section class="[ footnotes ]" role="doc-endnotes">
<h4>Notes:</h4>
<button>Expand Footnotes</button>
` -}}
{{ $content = replaceRE `^\S+` $stringToFind $append | safeHTML }}
{{ return $content }}
My ultimate goal is to create a collapsed by default footnote section that can be expanded by clicking on the button. The goal is to insert this button when the site compiles.This approach prints the desired markup, but only the the heading, the button and the pager at the bottom of the page…
My hunch is I’m doing something wrong w/ the regex, but I’m at a loss as to how to format the regex…
thanks in advance…