Skip to content

Instantly share code, notes, and snippets.

@MggMuggins
Created March 2, 2018 00:50
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 MggMuggins/ef92439b0070de48d6c8f48e2556a520 to your computer and use it in GitHub Desktop.
Save MggMuggins/ef92439b0070de48d6c8f48e2556a520 to your computer and use it in GitHub Desktop.
A little fish function that converts a github md doc to a pdf. Depends grip (https://github.com/joeyespo/grip) and wkhtmltopdf
# Usage is something like `render_md_to_pdf hi.md`
function md-to-pdf
set name (basename -s .md "$argv[1]")
grip "$argv[1]" --export "$name.html5"
sed -i 's/border:\([0-9]*\)px solid #ddd/border:\1px solid #FF0000/g' "$name.html5"
sed -i 's/#FF0000}\.markdown-body/#ddd}\.markdown-body/g' "$name.html5"
sed -i 's/FF0000/FFF/g' "$name.html5"
sed -i -e '/margin-top: 64px;/d' "$name.html5"
awk " \
BEGIN { count_o = 0; count_c = 0; } \
/<h3>/ { count_o += 1 } \
{ \
if (count_o == 0 || count_c >= 1) \
{ \
print
} \
} \
/<\/h3>/ { count_c += 1 } \
" "$name.html5" > "$name.html"
wkhtmltopdf -B 10 -L 10 -R 10 -T 10 "$name.html" "$name.pdf"
rm "$name.html"
rm "$name.html5"
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment