diff options
author | EuAndreh <eu@euandre.org> | 2025-04-17 09:04:19 -0300 |
---|---|---|
committer | EuAndreh <eu@euandre.org> | 2025-04-17 09:04:19 -0300 |
commit | f73a870fcb252eeefc57a8336f415997f6d7b1e6 (patch) | |
tree | 9b3a611f65133977733d396a7a183fac73ba539a | |
parent | src/adoc(add_linenums()): Do away with <pre>...</pre> table wrapper (diff) | |
download | adoc-f73a870fcb252eeefc57a8336f415997f6d7b1e6.tar.gz adoc-f73a870fcb252eeefc57a8336f415997f6d7b1e6.tar.xz |
src/adoc: Add fix_footnotes() to the pipeline
-rwxr-xr-x | src/adoc | 61 |
1 files changed, 61 insertions, 0 deletions
@@ -46,6 +46,66 @@ plaintext_links() { }' } +fix_footnotes() { + awk ' + match($0, /<sup class="footnote".*<\/sup>/) { + before = substr($0, 1, RSTART - 1) + middle = substr($0, RSTART, RLENGTH) + after = substr($0, RSTART + RLENGTH) + + n = split(middle, segments, "\"") + if (n != 13) { + print "Bad <sup ...> match" > "/dev/stderr" + exit 1 + } + id = substr(segments[4], length("_footnote_") + 1) + IDS[IDIDX++] = id + + ending = "</a>]</sup>" + match(middle, />[0-9]+<\/a>\]<\/sup>$/) + num = substr(middle, RSTART + 1, RLENGTH - length(ending) - 1) + + sup = sprintf("<sup role=\"doc-noteref\" id=\"ref:%s\">", id) + a = sprintf("<a href=\"#fn:%s\" rel=\"footnote\">",i id) + newmiddle = sup a num "</a></sup>" + printf "%s%s%s\n", before, newmiddle, after + next + } + /^<div class="footnote" id="_footnotedef_[0-9]+">$/ { + if (has_ol == 0) { + print "<ol>" + has_ol = 1 + } + next + } + match($0, /^<a href="#_footnoteref_[0-9]+">[0-9]+<\/a>/) { + id = IDS[FNIDX++] + content = substr($0, RLENGTH + length(". ") + 1) + + li = sprintf("<li role=\"doc-endnote\" id=\"fn:%s\">", id) + a = sprintf("<a role=\"doc-backlink\" href=\"#ref:%s\">", id) + print li content " " a "↩</a></li>" + next + } + has_ol == 1 && /^<\/div>$/ { + divcount++ + if (divcount == 2) { + print "</ol>" + has_ol = 0 + divcount = 0 + } + next + } + in_footnotes == 0 && $0 == "<div id=\"footnotes\">" { + in_footnotes = 1 + } + in_footnotes == 1 && $0 == "<hr>" { + next + } + { print } + ' +} + fix_header_anchor_position() { sed 's|^\(<h2 .*\)\(<a .*</a>\)\(.*\)\(</h2>\)$|\1\3\2\4|' } @@ -138,4 +198,5 @@ cat "$FILENAME" | runadoc | fix_header_anchor_position | add_linenums | + fix_footnotes | indent_4_blocks |