diff options
| author | Shulhan <ms@kilabit.info> | 2022-10-20 04:48:20 +0700 |
|---|---|---|
| committer | Shulhan <ms@kilabit.info> | 2022-10-20 22:09:31 +0700 |
| commit | 26c0d32b05eefb9b7040be69717d58e62bbdac2f (patch) | |
| tree | 86d02f3bd444b5148733cee1dca2756bff1c1f3a /html_backend.go | |
| parent | dc6f1e2a3e720b706dbf945ae6b608199f630fb4 (diff) | |
| download | asciidoctor-go-26c0d32b05eefb9b7040be69717d58e62bbdac2f.tar.xz | |
all: implement macro "footnote:"
Macro footnote grammar,
----
"footnote:" [ REF_ID ] "[" STRING "]"
----
In asciidoctor, footnote can be placed anywhere, even after WORD without
space in between.
The REF_ID, define the unique ID for footnote and can be used to reference
the previous footnote.
The first footnote with REF_ID, should have the STRING defined.
The next footnote with the same REF_ID, should not have the STRING
defined; if its defined, the STRING is ignored.
Diffstat (limited to 'html_backend.go')
| -rw-r--r-- | html_backend.go | 48 |
1 files changed, 48 insertions, 0 deletions
diff --git a/html_backend.go b/html_backend.go index e631448..4c2e467 100644 --- a/html_backend.go +++ b/html_backend.go @@ -393,6 +393,54 @@ func htmlWriteFooter(doc *Document, out io.Writer) { fmt.Fprint(out, "\n</div>\n</div>") } +// htmlWriteFootnote generate HTML content for footnote. +// Each unique footnote will have its id, so it can be referenced at footer. +func htmlWriteFootnote(el *element, out io.Writer) { + if len(el.ID) != 0 { + // The first footnote with explicit ID. + fmt.Fprintf(out, `<sup class="footnote" id="_footnote_%s">[<a id="_footnoteref_%d" class="footnote" href="#_footnotedef_%d" title="View footnote.">%d</a>]</sup>`, + el.ID, el.level, el.level, el.level) + + } else if len(el.key) != 0 { + // The first footnote without ID. + fmt.Fprintf(out, `<sup class="footnote">[<a id="_footnoteref_%d" class="footnote" href="#_footnotedef_%d" title="View footnote.">%d</a>]</sup>`, + el.level, el.level, el.level) + } else { + // The next footnote with same ID. + fmt.Fprintf(out, `<sup class="footnoteref">[<a class="footnote" href="#_footnotedef_%d" title="View footnote.">%d</a>]</sup>`, + el.level, el.level) + } +} + +func htmlWriteFootnoteDefs(doc *Document, out io.Writer) { + if len(doc.footnotes) == 0 { + return + } + + fmt.Fprint(out, "\n") + fmt.Fprint(out, `<div id="footnotes">`) + fmt.Fprint(out, "\n") + fmt.Fprint(out, `<hr>`) + fmt.Fprint(out, "\n") + + var ( + mcr *macro + ) + for _, mcr = range doc.footnotes { + fmt.Fprintf(out, `<div class="footnote" id="_footnotedef_%d">`, mcr.level) + fmt.Fprint(out, "\n") + fmt.Fprintf(out, `<a href="#_footnoteref_%d">%d</a>. `, mcr.level, mcr.level) + if mcr.content != nil { + mcr.content.toHTML(doc, out) + } + fmt.Fprint(out, "\n") + fmt.Fprint(out, `</div>`) + fmt.Fprint(out, "\n") + } + fmt.Fprint(out, `</div>`) + fmt.Fprint(out, "\n") +} + func htmlWriteHeader(doc *Document, out io.Writer) { fmt.Fprint(out, "\n<div id=\"header\">") |
