-
-
Save maikelthedev/54a91c21ed9623705fdce7bab2989742 to your computer and use it in GitHub Desktop.
# 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" |
I'm just getting my VimWiki set up, and this is fantastically useful. Thank you :)
Do you auto-generate TOCs at all? If so, how do you go about it? I can see the $toc$
placeholder in the template, but I'm missing the magic sauce that generates the content.
Edit: Also, I'm having to press <enter>
again after saving the file. Any idea how to avoid that unless pandoc errored?
"index.md" 20L, 522C written
Press ENTER or type command to continue_
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.
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.
@artkpv Sorry, had a namechange in the meantime.
Here the script:
https://gist.github.com/rattletat/4a1098d5c1e7c8db1fe52d4740076808
And here is the template:
https://github.com/tajmone/pandoc-goodies/tree/master/templates/html5/github
Although I'm not using
regex1
anymore for some reason. If you improve it, please tell me :)