Last active
December 17, 2022 22:27
-
-
Save maikelthedev/54a91c21ed9623705fdce7bab2989742 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# This is heavily based in the code here: | |
# https://gist.github.com/enpassant/0496e3db19e32e110edca03647c36541 | |
# Special thank you to the user enpassant for starting it https://github.com/enpassant | |
#!/bin/bash | |
SYNTAX="$2" | |
EXTENSION="$3" | |
OUTPUTDIR="$4" | |
INPUT="$5" | |
# Added ones | |
TEMPLATE_PATH="$7" | |
TEMPLATE_DEFAULT="$8" | |
TEMPLATE_EXT="$9" | |
ROOT_PATH="${10}" | |
[[ "$ROOT_PATH" = "-" ]] && ROOT_PATH='' | |
FILE=$(basename "$INPUT") | |
FILENAME=$(basename "$INPUT" ."$EXTENSION") | |
FILEPATH=${INPUT%$FILE} | |
OUTDIR=${OUTPUTDIR%$FILEPATH*} | |
OUTPUT="$OUTDIR"/$FILENAME | |
CSSFILENAME=$(basename "$6") | |
FULL_TEMPLATE="$TEMPLATE_PATH/$TEMPLATE_DEFAULT$TEMPLATE_EXT" | |
HAS_MATH=$(grep -o "\$\$.\+\$\$" "$INPUT") | |
if [ -n "$HAS_MATH" ]; then | |
MATH="--mathjax=https://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML" | |
else | |
MATH="" | |
fi | |
# >&2 echo "MATH: $MATH" | |
sed -r 's/(\[.+\])\(([^)]+)\)/\1(\2.html)/g' <"$INPUT" | pandoc $MATH --template="$FULL_TEMPLATE" -f "$SYNTAX" -t html -c "$CSSFILENAME" -M root_path:"$ROOT_PATH" | sed -r 's/<li>(.*)\[ \]/<li class="todo done0">\1/g; s/<li>(.*)\[X\]/<li class="todo done4">\1/g' > /tmp/crap.html | |
# With this you can have ![pic of sharks](file:../sharks.jpg) in your markdown file and it removes "file" | |
# and the unnecesary dot html that the previous command added to the image. | |
sed 's/file://g' < /tmp/crap.html | sed 's/jpg.html/jpg/g' > "$OUTPUT.html" |
Thanks; that's good to know.
I've been able to get TOC working with the help of a few threads (linked below). Basically, the trick is:
- Replace
$toc$
in the template with$table-of-contents$
- Add
--toc
to the pandoc command line in the conversion script. - Add
toc: false
to the metadata for files where a TOC is not required.
Unfortunately, it seems that the toc
metadata cannot be defaulted to false
. This isn't a big deal for me, since I don't have many documents yet. However, it should be possible to handle this in the export script by looking for a regex match and adding the --toc
argument conditionally.
References:
@rattletat Thanks! It works :)
There are two issues I have now. First is that it warns me about empty title. And second, how to make a link to my index.html page while I have folders hence it needs to be relative, without modifying each markdown file.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@giddie
I haven't used the toc parameter, but regarding the enter issue see here:
vimwiki/vimwiki#780
So this should be fixed as soon as dev is merged into the master branch.