Last active
July 2, 2021 03:32
-
-
Save CharlesSchimmel/4b8ff0632f60fc31aab7cab83ac6580d to your computer and use it in GitHub Desktop.
Convert Markdown Links to WikiLinks
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 | |
: ' | |
Context: Trying to use VimWiki in conjuction with Obsidian. Markdown links | |
are frequently interpreted as broken in Obsidian so Im switching back to | |
WikiLinks. This script successfully converted nearly all markdown links in a | |
modestly sized wiki | |
' | |
: ' | |
The Reggies: | |
The grep and sed reggies are pretty much the same, so Ill focus on the sed one: | |
Matching: | |
\[ inside of bracket literals | |
( capture... | |
[^[]+ one or more of any character that is not [ (to prevent greedy | |
matching when there is more than one link on a line) | |
) | |
\] | |
\( inside of paren literals | |
( capture... | |
[^[):]+ one or more of any char that is not [ or ) or : | |
(prevent greedy...etc and also naively ignore actual urls) | |
) | |
\) | |
Replacement | |
[[ Inside of double bracket literals, | |
\2 Insert the secord capture group (the actual link) | |
| Pipe literal | |
\1 Insert the first capture group (the description) | |
]] | |
' | |
egrep -lZr '\[[^\[]+\]\([^\[]+\)' \ | |
| xargs --null \ | |
sed -i -r 's,\[([^[]+)\]\(([^[):]+)\),[[\2|\1]],g' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment