Remove Obsidian wikilinks in Marked 2 (export to PDF/print)

I hope Obsidian devs will implement a native feature to easily format our markdown notes for exporting and printing purposes. Right now, I use Marked 2.

The goal here is to load a preprocessor in Marked 2 with a regex turning:

I love [[Bakery MOC#Donuts|big fat donuts]]!

into:

I love big fat donuts!

Step 1: Follow this tutorial.

Step 2: We modify the script from the tutorial.

Instead of:

input.gsub!(/\[\[(.*?)\]\]/) do |m|
  match = Regexp.last_match
  link_target = match[1]
  "\[\[[#{link_target}](thearchive://match/#{URI.escape(link_target)})\]\]"
end

print input

Write:

input.gsub!(/\[\[[^\]\[]*\|(.*?)\]\]/, '\1')

print input
6 Likes

Thanks for this.

After following your instructions my text goes from:

I love [[Bakery MOC#Donuts|big fat donuts]]!

to:

I love [[big fat donuts!]]

any thoughts?

This is somewhat related to this but if someone would like to have Obsidian [[WikiLinks]] with aliases visible and clickable within Marked app instead of have them removed i modified original preprocessor script to take care of just that. It will allow you to open such links directly in Obsidian.

Here it is with instructions. Maybe it will help someone.

https://gist.github.com/radekkozak/9b07af0ff3c90d4dc51d3a4ab41b5b8f

Side note

I’m using this along with Marked2 Custom Preprocessor option and pandoc for rendering my Obsidian notes for the output. Marked2 is very powerfull in that regard, allowing me to have References rendered from Zotero via autoupdated .bib file

full Args are (change your paths of course, and pick up style of your liking)

--citeproc -f markdown -M lang=pl-PL -t html5 --csl=/your/path/to/chicago.csl --bibliography=/your/path/to/Library.bib

With those in place sth like this below is possible. The note is in Polish so sorry for that but you can see references - in Chicago style - rendered at the bottom

3 Likes

Hello,

old thread but maybe someone stumbles upon it like I did.
I found this preprocessor script by @voostindie (Thank you!) which is a refined version of what @radekkozak made.