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" }