Add footnote support to allioli with Unicode superscripts
- Add footnote handling functions to allioli.awk: - printintroductionpar() for chapter 0 prologues - printfootnote() for displaying footnotes with proper formatting - Updated processline() to detect and route introductions, footnotes, and verses - Add -F flag to allioli.sh to disable footnotes - Strip superscript numbers (⁰¹²³⁴⁵⁶⁷⁸⁹) from verse text when -F is enabled - TSV format now supports footnotes in column 6 (number) and column 7 (text) - Footnotes use global numbering matching superscript references in verses
This commit is contained in:
88
allioli.awk
88
allioli.awk
@@ -151,6 +151,11 @@ function bookmatches(book, bookabbr, query) {
|
||||
}
|
||||
|
||||
function printverse(verse, word_count, characters_printed) {
|
||||
# Remove superscript footnote numbers if footnotes are disabled
|
||||
if (ENVIRON["ALLIOLI_NOFOOTNOTES"] != "" && ENVIRON["ALLIOLI_NOFOOTNOTES"] != "0") {
|
||||
gsub(/[⁰¹²³⁴⁵⁶⁷⁸⁹]+/, "", verse)
|
||||
}
|
||||
|
||||
if (ENVIRON["ALLIOLI_NOLINEWRAP"] != "" && ENVIRON["ALLIOLI_NOLINEWRAP"] != "0") {
|
||||
printf("%s\n", verse)
|
||||
return
|
||||
@@ -172,14 +177,91 @@ function printverse(verse, word_count, characters_printed) {
|
||||
printf("\n")
|
||||
}
|
||||
|
||||
function printintroductionpar(verse, word_count, characters_printed) {
|
||||
if (ENVIRON["ALLIOLI_NOLINEWRAP"] != "" && ENVIRON["ALLIOLI_NOLINEWRAP"] != "0") {
|
||||
printf("%s\n", verse)
|
||||
return
|
||||
}
|
||||
|
||||
word_count = split(verse, words, " ")
|
||||
characters_printed=8 #account for indents at beginning of each verse
|
||||
for (i = 1; i <= word_count; i++) {
|
||||
if (characters_printed + length(words[i]) + (characters_printed > 0 ? 1 : 0) > MAX_WIDTH) {
|
||||
printf("\n")
|
||||
characters_printed = 0
|
||||
}
|
||||
if (i != 1 && characters_printed > 0) { #need first check because we set characters_printed > 0 for first line only
|
||||
printf(" ")
|
||||
characters_printed++
|
||||
}
|
||||
printf("%s", words[i])
|
||||
characters_printed += length(words[i])
|
||||
}
|
||||
printf("\n")
|
||||
printed_intrudction=1
|
||||
}
|
||||
|
||||
function printfootnote(footnote_num, footnote, word_count, characters_printed) {
|
||||
if ( ENVIRON["ALLIOLI_NOFOOTNOTES"] != "" && ENVIRON["ALLIOLI_NOFOOTNOTES"] != "0"){
|
||||
return
|
||||
}
|
||||
else{
|
||||
if (ENVIRON["ALLIOLI_NOLINEWRAP"] != "" && ENVIRON["ALLIOLI_NOLINEWRAP"] != "0") {
|
||||
printf("\t\t%s%s\n", footnote_num, footnote)
|
||||
return
|
||||
}
|
||||
|
||||
if( length(footnote) < MAX_WIDTH - 17){
|
||||
for ( i=1; i <= MAX_WIDTH - length(footnote) - 1; i++){
|
||||
printf(" ")
|
||||
}
|
||||
printf("%s%s", footnote_num, footnote)
|
||||
}
|
||||
else{
|
||||
word_count = split(footnote, words, " ")
|
||||
printf("\n\t\t%s", footnote_num)
|
||||
characters_printed=17 #account for indents at beginning of each multiline footnote (2 tabs + footnote_num)
|
||||
for (i = 1; i <= word_count; i++) {
|
||||
if (characters_printed + length(words[i]) + (characters_printed > 0 ? 1 : 0) > MAX_WIDTH - 8 ) {
|
||||
printf("\n\t")
|
||||
characters_printed = 0
|
||||
}
|
||||
if (i != 1 && characters_printed > 0) { #Do not print empty space in front of first word for the first line (since characters_printed gets initialized > 0 we need this
|
||||
printf(" ")
|
||||
characters_printed++
|
||||
}
|
||||
printf("%s", words[i])
|
||||
characters_printed += length(words[i])
|
||||
}
|
||||
printf("\n")
|
||||
}
|
||||
printf("\n")
|
||||
}
|
||||
}
|
||||
|
||||
function processline() {
|
||||
if (printed_intrudction && $4 != 0){
|
||||
printf("\n\n")
|
||||
printed_intrudction=0
|
||||
}
|
||||
if (last_book_printed != $2) {
|
||||
print $1
|
||||
last_book_printed = $2
|
||||
}
|
||||
|
||||
printf("%d:%d\t", $4, $5)
|
||||
printverse($6)
|
||||
# Check if this is a footnote (column 6 is a number)
|
||||
if ($6 ~ /^[0-9]+$/) {
|
||||
printfootnote($6, $7)
|
||||
}
|
||||
# Check if this is an introduction (chapter 0)
|
||||
else if ($4 == 0){
|
||||
printf("\t")
|
||||
printintroductionpar($6)
|
||||
}
|
||||
# Regular verse
|
||||
else {
|
||||
printf("%d:%d\t", $4, $5)
|
||||
printverse($6)
|
||||
}
|
||||
outputted_records++
|
||||
}
|
||||
|
||||
|
||||
@@ -22,6 +22,7 @@ show_help() {
|
||||
echo
|
||||
echo " -l list books"
|
||||
echo " -W no line wrap"
|
||||
echo " -F no footnotes"
|
||||
echo " -h show help"
|
||||
echo
|
||||
echo " Reference types:"
|
||||
@@ -64,6 +65,9 @@ while [ $# -gt 0 ]; do
|
||||
elif [ "$1" = "-W" ]; then
|
||||
export ALLIOLI_NOLINEWRAP=1
|
||||
shift
|
||||
elif [ "$1" = "-F" ]; then
|
||||
export ALLIOLI_NOFOOTNOTES=1
|
||||
shift
|
||||
elif [ "$1" = "-h" ] || [ "$isFlag" -eq 1 ]; then
|
||||
show_help
|
||||
else
|
||||
|
||||
Reference in New Issue
Block a user