Last active
September 2, 2022 21:58
-
-
Save radekkozak/9b07af0ff3c90d4dc51d3a4ab41b5b8f to your computer and use it in GitHub Desktop.
Obsidian [[WikiLinks|with aliases]] preprocessor for Marked app
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
#!/usr/bin/ruby | |
# Modified for Obsidian WikiLinks by @radekkozak | |
# Original idea for The Archive @mjknght at zettelkasten.de | |
require 'uri' | |
VAULT_NAME = 'ZETTELKASTEN' | |
def class_exists?(class_name) | |
klass = Module.const_get(class_name) | |
return klass.is_a?(Class) | |
rescue NameError | |
return false | |
end | |
if class_exists? 'Encoding' | |
Encoding.default_external = Encoding::UTF_8 if Encoding.respond_to?('default_external') | |
Encoding.default_internal = Encoding::UTF_8 if Encoding.respond_to?('default_internal') | |
end | |
begin | |
input = STDIN.read.force_encoding('utf-8') | |
rescue | |
input = STDIN.read | |
end | |
input.gsub!(/\[\[(.*?)\]\]/) do |m| | |
match = Regexp.last_match | |
if match[1].include?('|') | |
splits = match[1].split('|') | |
"[#{splits[1]}](obsidian://vault/" + ::VAULT_NAME + "/#{URI.escape(splits[0])})" | |
else | |
"[#{match[1]}](obsidian://vault/" + ::VAULT_NAME + "/#{URI.escape(match[1])})" | |
end | |
end | |
print input |
This is fantastic. Thank you for sharing!
Hi Alex, sorry for belated reply but of course you're very welcome. I'm glad you find this helpful / cc @hollina
All best
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This is fantastic. Thank you for sharing!