Navigating Zettelkasten links in Marked 2
Has anyone found a way to get Marked 2 to navigate wikilinks? E.g. I would like to be able to view a note from my Zettelkasten in Marked, click a link referencing another note, and have Marked open that note.
Howdy, Stranger!
Comments
I haven't implemented this, but I think your best bet is (a) a pre-processor that replaces wiki links with Markdown links, or (b) JavaScript to achieve a similar effect but in the template/output. You can use
thearchive://match/<WIKI LINK HERE>to simulate clicking a wiki link from outside of the app.Author at Zettelkasten.de • https://christiantietze.de/
Hi there,
I do this using a preprocessor, just as @ctietze suggests.
Try the following ruby script, which strips the wiki link syntax, and adds the Markdown links. I had some help from the Marked developer when figuring this out, so credit goes to Brett Terpstra for this:
#!/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 inputHope it helps!
Just to add, you won’t need the
.txthere! A relic from a prior version…Amazing! Thanks for the script - It works
Hi! I'm a long time lurker around here, and this is my first comment.
I'm trying to modify the script posted above to make tags clickable in Marked in addition to WikiLinks, but I've had no success. Has anyone done this? I've tried the following, and some variations, but all have failed.
input.gsub!(/\#(.*$)/) do |m| match = Regexp.last_match tag = match[1] "[#{tag}](thearchive://search/#{URI.escape(tag)})" endI will appreciate any help or pointers.
@m_g What happens instead?
Author at Zettelkasten.de • https://christiantietze.de/
After some more experimenting, I managed to come up with a solution. Below is my modified version of @mjknght's Ruby script that makes tags clickable in Marked, in addition to WikiLinks.
#!/usr/bin/env 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 link_target = match[1] "[#{link_target}](thearchive://match/#{URI.escape(link_target)})" end input.gsub!(/#(\w+)/) do |m| match = Regexp.last_match tag = match[1] "🏷 [#{tag}](thearchive://search/#{URI.escape(tag)})" end print input