src/post2html (prefmt): Ties and newline stripping

I hate Markdown as a format for disciplined writing, especially when I want
macros (mostly semantic), indexes, and such.  I was originally going to use
LaTeX with Pandoc, but it lacks support for inline HTML and such, and I do
not want to distract too much from the work that I want to be doing.
master
Mike Gerwitz 2019-07-27 14:27:35 -04:00
parent 1f6ea32a45
commit 5b84305d8e
Signed by: mikegerwitz
GPG Key ID: 8C917B7F5DC51BA2
1 changed files with 32 additions and 1 deletions

View File

@ -83,6 +83,37 @@ hgroup-wrap()
}
# Pre-format Markdown files before they get to Pandoc
#
# These may be able to be implemented as Pandoc filters, but I haven't had
# the time to research that yet. This is actually a fitting real-world
# demonstration of incremental development / MVP that I'm writing about at
# the time that this comment was written (MyCustomBB Part I)!
prefmt()
{
awk '
triml {
gsub( /^ +/, "" )
triml = 0
}
# ties
{ $0 = gensub( /([^\\])~/, "\\1 ", "g" ) }
{ $0 = gensub( /\\~/, "~", "g" ) }
# TeX-style newline removal
/%$/ {
gsub( /%$/, "" )
printf "%s", $0
triml = 1
next
}
{ print }
'
}
# Generate HTML from post. Note that `pagetitle' is set just to suppress
# Pandoc warnings about it missing; it is unused.
main()
@ -97,7 +128,7 @@ main()
--base-header-level=1 \
-B <( src/mkheader post @__PAGE_TITLE__@ ) \
-A src/footer.tpl.htm \
< "$file" \
< <( prefmt < "$file" ) \
| src/h12title @__PAGE_TITLE__@ \
| hgroup-wrap "$date" "$file"
}