tag:support.markedapp.com,2011-09-11:/discussions/questions/9101-use-marked-to-open-nvalt-internal-linksMarked: Discussion 2018-10-19T05:39:15Ztag:support.markedapp.com,2011-09-11:Comment/449401862018-03-20T20:31:12Z2018-03-20T20:31:12ZUse Marked to open nvALT internal links<div><p>nvALT's editor parses wiki links out, and the preview does it with JavaScript (unless you're using a custom template). The JS that makes it happen looks like this:</p>
<pre>
<code><script>
var container = document.getElementById("wrapper");
container.innerHTML = container.innerHTML.replace(/\[\[(.*?)\]\]/,"<a href='nvalt://find/$1'>$1</a>");
</script></code>
</pre>
<p>A custom preprocessor that simply injected that into every preview would essentially add nvALT wiki support to Marked. However, it probably wouldn't help on GitHub. You'd need to write your own script that made the same regex conversion in the second line of the above script to the actual Markdown before pushing it to GitHub (though that could be added to a post-commit hook...).</p>
<p>-Brett</p></div>Bretttag:support.markedapp.com,2011-09-11:Comment/449401862018-03-28T16:12:29Z2018-03-28T16:12:31ZUse Marked to open nvALT internal links<div><p>Any suggestion of how could this be implemented in Pandoc? I use it as a custom processor in Marked 2, and having functional wiki links would make my note-taking system just perfect.</p></div>Davidtag:support.markedapp.com,2011-09-11:Comment/449401862018-03-28T19:20:42Z2018-03-28T19:20:42ZUse Marked to open nvALT internal links<div><p>David,</p>
<p>Add a preprocessor that does a simple search and replace. In Ruby for example:</p>
<pre>
<code> #!/usr/bin/ruby
$stdout.print STDIN.read.gsub(/\[\[(.*?)\]\]/,'[\1](nvalt://find/\1)');</code>
</pre></div>Bretttag:support.markedapp.com,2011-09-11:Comment/449401862018-07-14T21:02:11Z2018-07-14T21:02:13ZUse Marked to open nvALT internal links<div><p>Thanks, Brett. The preprocessor seems to crash every time there are non-ASCII characters. Any tip?</p>
<p>Thank you again,<br>
d</p></div>Davidtag:support.markedapp.com,2011-09-11:Comment/449401862018-07-16T15:41:56Z2018-07-16T15:41:56ZUse Marked to open nvALT internal links<div><p>You can force UTF-8 mode in recent versions of Ruby by changing the hash bang to this (first line of file):</p>
<pre>
<code>#!/usr/bin/env ruby
# encoding: utf-8
Encoding.default_external = Encoding::UTF_8
Encoding.default_internal = Encoding::UTF_8</code>
</pre>
<p>For complete UTF-8 compatibility across Ruby versions, here's a full script:</p>
<pre>
<code>#!/usr/bin/env ruby
# encoding: utf-8
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
$stdout.print input.gsub(/\[\[(.*?)\]\]/,'[\1](nvalt://find/\1)');</code>
</pre></div>Bretttag:support.markedapp.com,2011-09-11:Comment/449401862018-07-16T15:59:21Z2018-07-16T15:59:22ZUse Marked to open nvALT internal links<div><p>Hi Brett, thank you so much! Works like a charm out of the box!</p>
<p>One last question, that you can of course ignore. Is there's a way to make Marked open the linked file? Clicking the wiki-link opens the file in Nvalt.</p>
<p>Best,<br>
david</p></div>David Colmenarestag:support.markedapp.com,2011-09-11:Comment/449401862018-07-16T16:03:24Z2018-07-16T16:03:24ZUse Marked to open nvALT internal links<div><p>Well, the script is adding a link to nvalt://note_name, so it functions<br>
the way an nvALT wiki link would. If you want to link to the actual MD<br>
file, you'd want to change the <code>nvalt://</code> part to the path to the base<br>
notes folder, e.g. <code>file:///Users/your_user/Dropbox/nvALT/</code>. When you<br>
click one of those links, Marked will ask you how you want to handle it,<br>
and you can have it open in the same window, new window, or let Finder<br>
handle it. Note that opening in the same window does not give you a back<br>
button, it just completely replaces the current file.</p>
<p>-Brett</p></div>Bretttag:support.markedapp.com,2011-09-11:Comment/449401862018-07-16T16:18:23Z2018-07-16T16:18:24ZUse Marked to open nvALT internal links<div><p>The problem is that the link does not have an .md extension, so Marked can’t find the file...</p></div>David Colmenarestag:support.markedapp.com,2011-09-11:Comment/449401862018-07-16T16:29:01Z2018-07-16T16:29:01ZUse Marked to open nvALT internal links<div><p>Change this:</p>
<pre>
<code>$stdout.print input.gsub(/\[\[(.*?)\]\]/,'[\1](nvalt://find/\1)');</code>
</pre>
<p>to</p>
<pre>
<code>$stdout.print input.gsub(/\[\[(.*?)\]\]/,'[\1](file:///Users/[path/to/notes]/\1.md)');</code>
</pre></div>Bretttag:support.markedapp.com,2011-09-11:Comment/449401862018-07-16T16:32:20Z2018-07-16T16:32:21ZUse Marked to open nvALT internal links<div><p>Perfect! Thanks a ton!</p>
<p>d</p></div>David Colmenares