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 hidden or 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!
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
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