fixed bug in scripts/html.awk

previously, gemini lists would be converted wrong. for example:
* lorem
* ispum

would be turned into:
<ul><li>lorem</li></ul>
<ul><li>ispum</li></ul>

instead of:
<ul>
	<li>lorem</li>
	<li>ispum</li>
</ul>
This commit is contained in:
Abdullah Islam 2023-10-19 14:10:15 +06:00
parent 1cdc5c71a2
commit e29e3a663f
1 changed files with 29 additions and 24 deletions

View File

@ -2,9 +2,10 @@ BEGIN {
title = "techn0path - no title"
body = ""
subHeadings[0] = ""
insideRange = 0
}
/^[ ]*$/ { next }
/^#[^#]/ {
match($0, "^#[ ]*")
headingText = substr($0, RSTART + RLENGTH)
@ -52,6 +53,7 @@ BEGIN {
sub("\.gmi$", ".html", link)
if (description == "") description = link
gsub("&", "\\&amp;", description)
gsub("<", "\\&lt;", description)
gsub(">", "\\&gt;", description)
@ -59,29 +61,27 @@ BEGIN {
gsub("\"", "\\&quot;", description)
body = body sprintf("<a href='%s'>%s</a><br>\n", link, description)
next
}
/^```/ {
insideRange = !insideRange
body = body "<pre>\n"
if (insideRange) {
body = body "<pre>\n"
} else {
body = body "</pre>\n"
getline
while (match($0, "^```") == 0) {
gsub("&", "\\&amp;")
gsub("<", "\\&lt;")
gsub(">", "\\&gt;")
gsub("'", "\\&apos;")
gsub("\"", "\\&quot;")
body = body $0 "\n"
if (getline != 1) break
}
next
}
insideRange {
gsub("&", "\\&amp;")
gsub("<", "\\&lt;")
gsub(">", "\\&gt;")
gsub("'", "\\&apos;")
gsub("\"", "\\&quot;")
body = body $0 "\n"
body = body "</pre>\n"
next
}
@ -89,7 +89,7 @@ insideRange {
/^>/ {
body = body "<blockquote>\n"
while (getline == 1 && match($0, "^>[ ]*")) {
while (match($0, /^>[ ]*/) != 0) {
text = substr($0, RSTART + RLENGTH)
gsub("&", "\\&amp;", text)
@ -99,6 +99,8 @@ insideRange {
gsub("\"", "\\&quot;", text)
body = body text "<br>\n"
if (getline != 1) break
}
body = body "</blockquote>\n"
@ -108,7 +110,7 @@ insideRange {
/^\*/ {
body = body "<ul>\n"
while (getline == 1 && match($0, "^\\*[ ]*")) {
while (match($0, /^\*[ ]*/) != 0) {
gsub("&", "\\&amp;")
gsub("<", "\\&lt;")
gsub(">", "\\&gt;")
@ -116,12 +118,15 @@ insideRange {
gsub("\"", "\\&quot;")
body = body sprintf("<li>%s</li>\n", substr($0, RSTART + RLENGTH))
if (getline != 1) break
}
body = body "</ul>\n"
next
}
{
gsub("&", "\\&amp;")
gsub("<", "\\&lt;")
@ -150,14 +155,14 @@ END {
tocText = tocText "</ol> </details>\n"
}
sub(/(\.|\[|\]|\*)/, "\\&", sourcePath)
sub(/(\.|\[|\]|\*)/, "\\&", outputPath)
navbarText = genNavbarHTML(FILENAME, sourcePath, outputPath)
stylesheetPath = getRelativePath(dirname, outputPath "/style.css")
dirname = getDirname(FILENAME)
gsub(/(\.|\[|\]|\*)/, "\\&", sourcePath)
gsub(sourcePath, outputPath, dirname)
gsub(sourcePath, outputPath, filename)
sub("^" sourcePath, outputPath, dirname)
stylesheetPath = getRelativePath(dirname, outputPath "/style.css")
printf "<!DOCTYPE html>\n\
<html>\n\