Skip to content

Instantly share code, notes, and snippets.

@mjknght
Last active May 24, 2021 09:09
Show Gist options
  • Save mjknght/25a7ce3c06ea329ed54b82094326397b to your computer and use it in GitHub Desktop.
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.
#!/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
@mjknght
Copy link
Author

mjknght commented May 24, 2021

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment