Blob
1 # gmi2txt3 gmi2txt is a small script to format a text/gemini page. needs par(1)5 #!/usr/bin/awk -f7 BEGIN {8 in_pre = 010 title1 = "sed s/./=/g"11 title2 = "sed s/./-/g"12 parl = "par 72p2"13 pari = "par 72p3 | sed '2,$s/^ \\*/ /'"14 parq = "par 72p2"15 par = "par 72"16 }18 !in_pre && /^```/ {19 in_pre = 120 print $021 next22 }23 in_pre && /^```/ {24 in_pre = 025 print $026 next27 }28 in_pre { print $0; next }30 // {31 # print a blank line between links and other line32 # types, unless there's already a blank line.34 if (last_was_link && !match($0, "^[ \t]*$")) {35 print "";36 }37 }39 /^=>/ {40 last_was_link = 142 $0 = gensub("=> *", "", 1)43 link = $144 $1 = ""45 text = gensub("^ *", "", 1)46 if (text == "")47 text = link49 printf("~ %s\n", text) | parl50 printf("%s\n", link)51 close(parl)52 next53 }55 // { last_was_link = 0 }57 /^###/ {58 t = gensub("### *", "", "1")59 printf("-%s-\n", t)60 next61 }63 /^##/ {64 t = gensub("## *", "", 1)65 print t66 print t | title267 close(title2)68 next69 }71 /^#/ {72 t = gensub("# *", "", 1)73 print t74 print t | title175 close(title1)76 next77 }79 /^>/ {80 print $0 | parq81 close(parq)82 next83 }85 /^\*/ {86 printf(" %s", $0) | pari87 close(pari)88 next89 }91 // {92 print $0 | par93 close(par)94 }96 END {97 if (in_pre)98 print "```"99 }