Last active
July 10, 2021 16:08
-
-
Save CharlesSchimmel/ee8a421544220a4cbc1d7ef9d5b1e32b to your computer and use it in GitHub Desktop.
Convert Obsidian-Markdown Notes to HTML
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
#!/bin/bash | |
: ' | |
Pretty roughly converts a single folder of notes from Obsidian/Zettlr markdown | |
(markdown + wikilinks) to HTML with pandoc. The real trick here is | |
re-converting WikiLinks back into something that pandoc will work with. | |
It does not handle percent-encoding for characters other than spaces for | |
filenames or headers. | |
' | |
mkdir -p html | |
find . -maxdepth 1 -name '*.md' -print0 | xargs --null -I{} cp {} html/ | |
# Replace WikiLinks with Markdown links | |
sed -r -i 's,\[\[([^\[\|]+)\|([^\[]+)\]\],[\2](\1),g' html/* | |
sed -r -i 's,\[\[([^\[\|]+)\]\],[\1](\1),g' html/* | |
# Replace spaces in links with %20 | |
sed -r -i ':l s,\]\(([^ )#]+) +,](\1%20,;tl' html/* | |
# Replace spaces in archors with dashes | |
sed -r -i ':l s,\]\((.+)#([^ )]+) +,](\1#\2-,;tl' html/* | |
find html -exec pandoc {} -f markdown -t html -o {} \; | |
rename .md '' html/* |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment