-
-
Save radekkozak/9b07af0ff3c90d4dc51d3a4ab41b5b8f to your computer and use it in GitHub Desktop.
#!/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 |
Side note
I'm using this along with Marked2 Custom Preprocessor option and pandoc
for rendering my Obsidian notes for the output, be it PDF, ODT, DOCX, RTF or HTML. Marked2 is very powerfull in that regard, allowing me to have References rendered from Zotero via autoupdated .bib file. I use that capabilities mostly for bigger Outlines, essays or papers where such case is a must.
full Args are (change your paths of course, and pick up style of your liking)
--citeproc -f markdown -M lang=pl-PL -t html5 --csl=/your/path/to/chicago.csl --bibliography=/your/path/to/Library.bib
With those in place sth like below is possible. The note is in Polish so sorry for that but you can see references - in Chicago style - rendered at the bottom
This is fantastic. Thank you for sharing!
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
This simple preprocessor will make Obsidian [[WikiLinks]] clickable within Marked2 app.
Links will open appropriate file in Obsidian via its URL scheme.
Instructions:
VAULT_NAME
constant to the vault of your choice and save the changesThat's it.
Script should take care of your WikiLinks along with aliases if there are some