Previewing Without Double-square-brackets

Kevin Kleinfelter's Avatar

Kevin Kleinfelter

22 Mar, 2017 03:51 PM

I often use Marked2 to preview my nvalt notes. Nvalt notes are often littered with [[HyperLinkThis]]. That renders as ugly plain text in Marked2.

I'd like to set up Marked2 with a preprocessor, so that "[[HyperLinkThis]]" gets replaced with "[HyperLinkThis](nv://HyperLinkThis)".

i.e. I want the text sent from nvalt (or any other editing program) to be run through a filter to transform non-markdown markup into proper markdown markup.

I think this might be possible via the Advanced preferences tab and a custom preprocessor. Has someone done this before, so I don't reinvent the wheel? Can someone point me in the right direction?

  1. Support Staff 1 Posted by Brett on 22 Mar, 2017 09:28 PM

    Brett's Avatar

    This is possible with a basic preprocessor that does a regular
    expression substitution. Something like this in Ruby:

     #!/usr/bin/ruby
     # encoding: utf-8
     require 'cgi'
    
     input = STDIN.read.force_encoding('utf-8')
    
     puts input.gsub(/\[\[(.*?)\]\]/) {|m|
       match = Regexp.last_match
       "[#{match[1]}](nvalt://#{CGI.escape(match[1])})"
     }
    

    I can help you set that up if needed.

    -Brett

  2. 2 Posted by Kevin Kleinfelt... on 23 Mar, 2017 10:48 PM

    Kevin Kleinfelter's Avatar

    This is great. Thanks!

Reply to this discussion

Internal reply

Formatting help / Preview (switch to plain text) No formatting (switch to Markdown)

Attaching KB article:

»

Attached Files

You can attach files up to 10MB

If you don't have an account yet, we need to confirm you're human and not a machine trying to post spam.

Keyboard shortcuts

Generic

? Show this help
ESC Blurs the current field

Comment Form

r Focus the comment reply box
^ + ↩ Submit the comment

You can use Command ⌘ instead of Control ^ on Mac