From 5b84305d8e0223f163c1f5ec606d6e96c3b5fc77 Mon Sep 17 00:00:00 2001 From: Mike Gerwitz Date: Sat, 27 Jul 2019 14:27:35 -0400 Subject: [PATCH] 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. --- src/post2html | 33 ++++++++++++++++++++++++++++++++- 1 file changed, 32 insertions(+), 1 deletion(-) diff --git a/src/post2html b/src/post2html index 803fef7..8fd821f 100755 --- a/src/post2html +++ b/src/post2html @@ -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" }