Skip to content

Instantly share code, notes, and snippets.

@zot
Last active November 9, 2021 16:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zot/579003a404d8b7c421923d17d63bc640 to your computer and use it in GitHub Desktop.
Save zot/579003a404d8b7c421923d17d63bc640 to your computer and use it in GitHub Desktop.
format markdown docs with https://jez.io/pandoc-markdown-css-theme/ and add TOC sidebar
#!/bin/sh
# format markdown docs with https://jez.io/pandoc-markdown-css-theme/ and add TOC sidebar
# removes the large margin at the top of the body
if [ $# = 0 -o "$1" = --help ]; then
cat <<here
Usage: $(basename $(realpath "$0")) [--help] MARKDOWNFILE
Outputs HTML file from MARKDOWNFILE.
Formats MARKDOWNFILE with jez's template.
Shows a table of contents on the side.
here
exit
fi
iid=$(mktemp)
docker build - --iidfile=$iid -q >/dev/null <<here
FROM debian:buster
RUN apt-get update \
&& apt-get install -y pandoc git
RUN mkdir /work /md \
&& cd /md \
&& git clone https://github.com/jez/pandoc-markdown-css-theme.git
RUN sed 's/^.*--title-margin-top:.*$/ --title-margin-top: 0;/' < /md/pandoc-markdown-css-theme/public/css/theme.css > /tmp/theme.css \
&& mv /tmp/theme.css /md/pandoc-markdown-css-theme/public/css
here
image=$(cat $iid)
dir=$(dirname $(realpath "$1"))
file=$(basename "$1")
config=/md/pandoc-markdown-css-theme
docker run --rm --read-only -v "$dir":/work $image pandoc \
--katex \
--from markdown+tex_math_single_backslash \
--to html5+smart \
--template=$config/template \
--css=$config/public/css/theme.css \
--css=$config/public/css/skylighting-solarized-theme.css \
--self-contained \
--resource-path=/work \
--metadata=title-margin-top:0px \
--variable=fontsize:72 \
--toc \
"/work/$file"
@zot
Copy link
Author

zot commented Nov 9, 2021

This uses docker for a spiffy "zero-install" experience...

@zot
Copy link
Author

zot commented Nov 9, 2021

added --rm to docker run

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment