From c7c5f72d49645ac1fbd652ddcb7a5dfe739620e0 Mon Sep 17 00:00:00 2001 From: Nulo Date: Sun, 13 Mar 2022 17:50:32 -0300 Subject: [PATCH] exportmd --- .local/bin/exportmd | 77 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 77 insertions(+) create mode 100755 .local/bin/exportmd diff --git a/.local/bin/exportmd b/.local/bin/exportmd new file mode 100755 index 0000000..a26c50e --- /dev/null +++ b/.local/bin/exportmd @@ -0,0 +1,77 @@ +#!/bin/sh -e + +html() { + echo "" + if test -n "$style"; then + echo " + +" + 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 "" >> "$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