Last active
May 24, 2021 09:09
-
-
Save mjknght/25a7ce3c06ea329ed54b82094326397b to your computer and use it in GitHub Desktop.
A preprocessor for Marked that adds wiki links to The Archive note previews.
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 | |
require 'uri' | |
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 | |
"[#{match[1]}](thearchive://match/#{URI.escape(match[1])}.txt)" | |
end | |
print input |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Some instructions for the use of this script can be found on Zettelkasten.de.
A preprocessor for use with Obsidian that also handles aliases, along with instructions, has been produced by @radekkozak and can be found here.