md2tex/md2parallel.sh
2024-10-02 02:26:03 +02:00

39 lines
1.2 KiB
Bash
Executable File
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#!/bin/bash
# converts aqoaba markdown into tex
# TODO
# - [ ] formatting scripture https://tex.stackexchange.com/a/652451/264579
# - [ ] do I even need mutliple verse environments?
USAGE="""USAGE:
$(basename $0) markdown-file"""
if [ $# -ne 1 ] ; then echo "$USAGE" && exit 1; fi
INFILE=$1
# remove any suffix https://stackoverflow.com/a/36341390
BASENAME=$( basename "${INFILE%.*}" )
DIRNAME=$( dirname "$INFILE" )
#echo $BASENAME
#echo $DIRNAME
KEEP_TMP_FILES=0
#set -x
#set -e
#
# TODO
# check if same number of paragraphs?
# convert md to html
pandoc --wrap=none -f markdown $DIRNAME/${BASENAME}.md -t html -o ${BASENAME}.html
# convert html to tex
#sed -i '' 's@<p>@\n\\pstart\n@' ${BASENAME}.html
#sed -i '' 's@</p>@\n\\pend@' ${BASENAME}.html
sed -i '' 's@<p>@\n\\pend\\pstart\n@' ${BASENAME}.html
sed -i '' 's@</p>@@' ${BASENAME}.html
sed -i '' 's@“@\\enquote{@g' ${BASENAME}.html
sed -i '' 's@”@}@g' ${BASENAME}.html
sed -i '' 's@<h1.*">@\\section[@' ${BASENAME}.html
sed -i '' 's@</h1>@]@' ${BASENAME}.html
sed -i '' 's@<h2.*">@{@' ${BASENAME}.html
sed -i '' 's@</h2>@}@' ${BASENAME}.html
sed -i '' "s@@'@g" ${BASENAME}.html
mv ${BASENAME}.html ${BASENAME}.tex
cat ${BASENAME}.tex && rm ${BASENAME}.tex