Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.