#!/usr/bin/awk -f # originally from gemini://hubbz.de/en/floss/2021-02-13-convert-gemini-text-to-html.gmi # licenced under the MIT license # the string in the BEGIN statement is modified to link to my stylesheet, to # add a page title, and to add navigation links. the link parsing function has # been modified to automatically rewrite images to be inline and to # automatically fix non-relative links (i.e. links to /example will be # rewritten to /gemini/example). the END statement has been modified to add a # footer telling the reader what gemini is and suggesting to browse with a real # browser. BEGIN { print "\n\ \n\
\n\ \n\ \n\ \n\"; next } in_pre && /^```/ { in_pre = 0; print ""; next } in_pre { print san($0); next } /^###/ { output("
", substr($0, 2), ""); next } /^\*/ { output("
", $0, "
"); next } END { if (in_list) print "" if (in_pre) print "" print "" && content == "")
return;
printf("%s%s%s\n", ot, san(content), ct);
}
function output_link(link, content) {
if (in_list) {
in_list = 0;
print "";
}
# If it's a local gemini file, link to the html:
if((link !~ /^[a-zA-Z]*:\/\//) && (link ~ /\.gmi$/)){
sub(/\.gmi$/, ".html", link)
}
# if it's an absolute link (i.e. "/folder/file.gmi") be sure to prepend the proper web directory
if(link ~ /^\//){
link = "/gemini" link
}
if(link ~ /\.(png|jpg|webp)$/){
printf("
%s
\n", link, link, trim(san(content))); }else{ if (content == "") content = link; printf("⮩ %s