From f73a870fcb252eeefc57a8336f415997f6d7b1e6 Mon Sep 17 00:00:00 2001 From: EuAndreh Date: Thu, 17 Apr 2025 09:04:19 -0300 Subject: src/adoc: Add fix_footnotes() to the pipeline --- src/adoc | 61 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 61 insertions(+) diff --git a/src/adoc b/src/adoc index 8270a44..f99e7d5 100755 --- a/src/adoc +++ b/src/adoc @@ -46,6 +46,66 @@ plaintext_links() { }' } +fix_footnotes() { + awk ' + match($0, //) { + 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 match" > "/dev/stderr" + exit 1 + } + id = substr(segments[4], length("_footnote_") + 1) + IDS[IDIDX++] = id + + ending = "]" + match(middle, />[0-9]+<\/a>\]<\/sup>$/) + num = substr(middle, RSTART + 1, RLENGTH - length(ending) - 1) + + sup = sprintf("", id) + a = sprintf("",i id) + newmiddle = sup a num "" + printf "%s%s%s\n", before, newmiddle, after + next + } + /^
$/ { + if (has_ol == 0) { + print "
    " + has_ol = 1 + } + next + } + match($0, /^[0-9]+<\/a>/) { + id = IDS[FNIDX++] + content = substr($0, RLENGTH + length(". ") + 1) + + li = sprintf("
  1. ", id) + a = sprintf("", id) + print li content " " a "↩
  2. " + next + } + has_ol == 1 && /^<\/div>$/ { + divcount++ + if (divcount == 2) { + print "
" + has_ol = 0 + divcount = 0 + } + next + } + in_footnotes == 0 && $0 == "
" { + in_footnotes = 1 + } + in_footnotes == 1 && $0 == "
" { + next + } + { print } + ' +} + fix_header_anchor_position() { sed 's|^\(

\)\(.*\)\(

\)$|\1\3\2\4|' } @@ -138,4 +198,5 @@ cat "$FILENAME" | runadoc | fix_header_anchor_position | add_linenums | + fix_footnotes | indent_4_blocks -- cgit v1.2.3