165 lines
3.4 KiB
Awk
Executable File
165 lines
3.4 KiB
Awk
Executable File
BEGIN {
|
|
title = "techn0path - no title"
|
|
body = ""
|
|
subHeadings[1] = ""
|
|
}
|
|
|
|
/^#[^#]/ {
|
|
match($0, "^#[ ]*")
|
|
headingText = substr($0, RSTART + RLENGTH)
|
|
body = body sprintf("<h1>%s</h1>\n", headingText)
|
|
title = headingText
|
|
next
|
|
}
|
|
|
|
/^##[^#]/ {
|
|
match($0, "^##[ ]*")
|
|
headingText = substr($0, RSTART + RLENGTH)
|
|
body = body sprintf("<h2 id='%s'>%s</h2>\n\
|
|
<a href='#%s'>Permalink</a><br/><br/>\n", \
|
|
toFilename(headingText), \
|
|
headingText, \
|
|
toFilename(headingText))
|
|
|
|
subHeadings[length(subHeadings)] = headingText
|
|
next
|
|
}
|
|
|
|
/^###[^#]/ {
|
|
match($0, "^###[ ]*")
|
|
headingText = substr($0, RSTART + RLENGTH)
|
|
body = body sprintf("<h3>%s</h3>\n", headingText)
|
|
next
|
|
}
|
|
|
|
/^=>/ {
|
|
match($0, "^=>[ ]*[^ ]*")
|
|
link = substr($0, 3, RLENGTH - 2)
|
|
description = substr($0, RSTART + RLENGTH)
|
|
sub("^[ ]*", "", link)
|
|
sub("^[ ]*", "", description)
|
|
|
|
if (description == "") description = link
|
|
if (link !~ "^[a-zA-Z0-9_]*:")
|
|
sub("\.gmi$", ".html", link)
|
|
|
|
gsub("&", "\\&", description)
|
|
gsub("<", "\\<", description)
|
|
gsub(">", "\\>", description)
|
|
gsub("'", "\\'", description)
|
|
gsub("\"", "\\"", description)
|
|
|
|
body = body sprintf("<a href='%s'>%s</a><br>\n", link, description)
|
|
next
|
|
}
|
|
|
|
/^```/ {
|
|
body = body "<pre>\n"
|
|
getline
|
|
while ($0 !~ "^```") {
|
|
gsub("&", "\\&")
|
|
gsub("<", "\\<")
|
|
gsub(">", "\\>")
|
|
gsub("'", "\\'")
|
|
gsub("\"", "\\"")
|
|
|
|
body = body $0 "\n"
|
|
if (getline != 1) break
|
|
}
|
|
body = body "</pre>\n"
|
|
next
|
|
}
|
|
|
|
/^>/ {
|
|
body = body "<blockquote>\n"
|
|
while (match($0, "^>[ ]*")) {
|
|
text = substr($0, RSTART + RLENGTH)
|
|
gsub("&", "\\&", text)
|
|
gsub("<", "\\<", text)
|
|
gsub(">", "\\>", text)
|
|
gsub("'", "\\'", text)
|
|
gsub("\"", "\\"", text)
|
|
|
|
body = body text "<br>\n"
|
|
if (getline != 1) break
|
|
}
|
|
body = body "</blockquote>\n"
|
|
next
|
|
}
|
|
|
|
/^\*/ {
|
|
body = body "<ul>\n"
|
|
while (match($0, "^\\*[ ]*")) {
|
|
gsub("&", "\\&")
|
|
gsub("<", "\\<")
|
|
gsub(">", "\\>")
|
|
gsub("'", "\\'")
|
|
gsub("\"", "\\"")
|
|
|
|
body = body sprintf("<li>%s</li>\n", substr($0, RSTART + RLENGTH))
|
|
if (getline != 1) break
|
|
}
|
|
body = body "</ul>\n"
|
|
next
|
|
}
|
|
|
|
{
|
|
gsub("&", "\\&")
|
|
gsub("<", "\\<")
|
|
gsub(">", "\\>")
|
|
gsub("'", "\\'")
|
|
gsub("\"", "\\"")
|
|
body = body sprintf("<p>%s</p>\n", $0)
|
|
}
|
|
|
|
END {
|
|
if (length(subHeadings) == 1 && subHeadings[1] == "")
|
|
delete subHeadings
|
|
|
|
if (length(subHeadings) > 0) {
|
|
tocText = "\n\
|
|
<details id='toc'>\n\
|
|
<summary>Table of content</summary>\n\
|
|
<ol>\n"
|
|
|
|
for (i in subHeadings)
|
|
tocText = tocText sprintf("<li><a href='#%s'>%s</a></li>\n", toFilename(subHeadings[i]), subHeadings[i])
|
|
|
|
tocText = tocText "</ol> </details>\n"
|
|
}
|
|
|
|
navbarText = genNavbarHTML(FILENAME, "src/", "html/")
|
|
|
|
printf "<!DOCTYPE html>\n\
|
|
<html>\n\
|
|
<head>\n\
|
|
<title>%s</title>\n\
|
|
\n\
|
|
<meta name='author' content='techn0path' />\n\
|
|
<meta name='referrer' content='no-referrer' />\n\
|
|
<meta name='viewpoint' content='width=device-width,initial-scale=1.0' />\n\
|
|
\n\
|
|
<style>\n\
|
|
body { margin: 20px; }\n\
|
|
#content { max-width: 80ch; }\n\
|
|
.permalink { margin-left: 15px; }\n\
|
|
</style>\n\
|
|
</head>\n\
|
|
<body>\n\
|
|
<header>\n\
|
|
%s\n\
|
|
</header><hr>\n\
|
|
<article id='content'>\n\
|
|
%s\n\
|
|
%s\n\
|
|
</article>\n\
|
|
<hr>\n\
|
|
<p>If you have any suggestions, let me know at <a href='mailto:logicartist123@gmail.com'>logicartist123@gmail.com</a>. Sorry, I still use GMail. :/</p>\n\
|
|
</body>\n\
|
|
</html>", \
|
|
title, \
|
|
navbarText, \
|
|
tocText, \
|
|
body
|
|
}
|