This commit is contained in:
Cat /dev/Nulo 2022-03-13 17:50:32 -03:00
parent eb8542f040
commit c7c5f72d49

77
.local/bin/exportmd Executable file
View file

@ -0,0 +1,77 @@
#!/bin/sh -e
html() {
echo "<meta charset=utf8>"
if test -n "$style"; then
echo "
<style>
html, body {
margin: 0;
padding: 0;
font-family: 'Liberation Sans', sans-serif;
font-size: 16px;
line-height: 1.3;
}
h1, h2, h3, h4, h5, h6 {
text-align: center;
}
img {
max-width: 100%;
}
blockquote {
border-left: 3px solid;
margin-left: 1em;
padding-left: 1em;
}
</style>
"
fi
cmark --unsafe < "$1"
}
format="$1"
input="$2"
if test ! -f "$input"; then
echo "no existe el archivo \`$input\`."
exit 1
fi
output="$(dirname "$input")/$(basename "$input" .md).$format"
if grep "TODO|XXX" "$input" >/dev/null; then
echo "Ojo, ¡todavía tenés TODOs o XXXs!"
fi
if test "$format" = epub -o "$format" = rtf -o "$format" = docx; then
htmlfile="${input%.md}.html"
style=true html "$input" > "$htmlfile"
#if which pandoc >/dev/null; then
# pandoc --reference-doc=$HOME/template.docx -s -o "$output" "$htmlfile"
if which libreoffice >/dev/null; then
echo libreoffice --headless --writer --convert-to "$format" "$htmlfile"
libreoffice --headless --writer --convert-to "$format" "$htmlfile"
else
echo "No tengo libreoffice para convertir a $format."
rm "$htmlfile"
exit 1
fi
rm "$htmlfile"
elif test "$format" = html; then
style=true html "$input" > "$output"
elif test "$format" = standalone.html; then
html "$input" > "$output"
echo "<style>" >> "$output"
cat ~/proy/sitio/drip.css >> "$output"
echo "</style>" >> "$output"
elif test "$format" = pdf; then
style=true html "$input" | weasyprint -u "$(dirname "$input")" - "$output"
else
echo "no conozco el formato \`$format\`."
exit 1
fi