Skip to content

Instantly share code, notes, and snippets.

@zeta709
Last active February 2, 2022 14:47
Show Gist options
  • Select an option

  • Save zeta709/c5119edec069f9c3b57695d09eeed410 to your computer and use it in GitHub Desktop.

Select an option

Save zeta709/c5119edec069f9c3b57695d09eeed410 to your computer and use it in GitHub Desktop.
Simple markdown server; pandoc;
mdserver() {
if [ "$#" -ne 1 ]; then
echo "Usage: mdserver file.md"
return
fi
local TMP="$HOME/tmp"
mkdir -p "$TMP" || return
local CSS="markdown_pandoc.css"
if [ ! -r "$TMP/$CSS" ]; then
(
cd "$TMP" || return
if [ ! -r markdown.css ]; then
curl -O "https://guides.github.com/components/primer/markdown.css" || return
fi
sed 's/.markdown-//g' markdown.css > "$CSS" || return
)
fi
local OPT="-f markdown_github -t html5 --self-contained --standalone"
pandoc ${=OPT} --css "$TMP/$CSS" -o "$TMP/index.html" -- "$1" || return
(cd "$TMP" && python3 -m http.server)
}
@zeta709
Copy link
Author

zeta709 commented Feb 2, 2022

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