Added Pandoc-powered Markdown previewer!
This commit is contained in:
parent
bce092c777
commit
7c13324acc
1 changed files with 28 additions and 0 deletions
28
scripts/md-previewer
Executable file
28
scripts/md-previewer
Executable file
|
|
@ -0,0 +1,28 @@
|
|||
#!/usr/bin/env bash
|
||||
DATADIR="$HOME/.local/share/md-previewer"
|
||||
[ ! -d "$DATADIR" ] && mkdir -p "$DATADIR"
|
||||
|
||||
CSS="$DATADIR/pub.css"
|
||||
if [ ! -e "$CSS" ]; then
|
||||
pushd "$DATADIR"
|
||||
wget https://github.com/manuelp/pandoc-stylesheet/raw/acac36b976966f76544176161ba826d519b6f40c/pub.css \
|
||||
|| (echo "ERROR: Unable to fetch CSS!" >&2) || exit 1
|
||||
popd
|
||||
fi
|
||||
|
||||
case $(uname | tr '[:upper:]' '[:lower:]') in
|
||||
darwin)
|
||||
OPEN=open
|
||||
;;
|
||||
linux)
|
||||
OPEN=xdg-open
|
||||
;;
|
||||
esac
|
||||
|
||||
command -v pandoc || (echo "ERROR: Pandoc not found!" >&2) || exit 1
|
||||
HTML=$(sed 's/\.md\s*$/.html/' <<<"$1")
|
||||
pandoc "$1" -s -c "$CSS" -o "$HTML"
|
||||
|
||||
command -v "$OPEN" || (echo "WARN: Can't open HTML with \"$OPEN\"! " \
|
||||
"Please navigate to file://$(realpath "$HTML")" >&2)
|
||||
"$OPEN" "$HTML"
|
||||
Loading…
Add table
Add a link
Reference in a new issue