md2tex/md2parallel.sh
2024-10-09 00:14:01 +02:00

48 lines
1.5 KiB
Bash
Executable File
Raw Permalink 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
# check if on linux or macos
if [[ $(uname) == "Linux" ]]
then
SED_CMD="sed -i"
elif [[ $(uname) == "Darwin" ]]
then
SED_CMD="sed -i ''"
fi
#$SED_CMD 's@<p>@\n\\pstart\n@' ${BASENAME}.html
#$SED_CMD 's@</p>@\n\\pend@' ${BASENAME}.html
$SED_CMD 's@<p>@\n\\pend\\pstart\n@' ${BASENAME}.html
$SED_CMD 's@</p>@@' ${BASENAME}.html
$SED_CMD 's@“@\\enquote{@g' ${BASENAME}.html
$SED_CMD 's@”@}@g' ${BASENAME}.html
$SED_CMD 's@<h1.*">@\\section{@' ${BASENAME}.html
$SED_CMD 's@</h1>@}@' ${BASENAME}.html
$SED_CMD 's@<h2.*">@\\pend\\pstart\\subsection{@' ${BASENAME}.html
$SED_CMD 's@</h2>@}@' ${BASENAME}.html
$SED_CMD "s@@'@g" ${BASENAME}.html
mv ${BASENAME}.html ${BASENAME}.tex
cat ${BASENAME}.tex && rm ${BASENAME}.tex
if [[ -f ${BASENAME}.html\'\' ]] ; then rm ${BASENAME}.html\'\' ; fi