How can I make obsidian to use commonmark links specification by default rather than wikilink?

First, search the help docs and this forum. Maybe your question has been answered! The debugging steps can help, too. Still stuck? Delete this line and proceed.

What I’m trying to do

I would like Obsidian to use commonmark specification by default when I copy and paste a picture or text file within a note.

Things I have tried

Copying and pasting a picture or a text file within a note creates a wikilink instead of a link with the commonmark specification.

With commonmark specification I mean the third option described on
out of these:
Wikilink 1. [[Test 2|this one]]
Markdown 2. [this one] (Test%202)
CommonMark 3. [this one] (<Test 2>)


In “Files & Links” settings, have the Use [[Wikilinks]] option deactivated to generate Markdown links.

Regarding the specific option no. 3, you could use Linter’s “Custom Regex Replacement” feature to “fix” the missing <>.

1 Like

I just tried this:
regex to find: ![(.)]([^<>])
regex to replace: !([(.)])(<(.)>)

The current note has this link:
![Pasted image 20230917184634.png](Pasted%20image%2020230917184634.png)

Saving the note to make Linter work updates the link and leaves it as dislpayed below:

That means, Linter does not work as expected.

Do you know how to fix it?

Sure, Linter does work as expected: it just does what you tell it. :wink:

The correct sequence is: (!\[[^\]]+\]\()([^)]+)\) + gm + $1<$2>).

You need to capture the separate parts and then to “re-assemble” your way.

I just found out that the <> will be “doubled” every time you save the file. Working on the correct solution…

Here we go. The final version is: (!?\[[^\]]+\]\()\<?([^>)]+)\>?\) + gm + $1<$2>) .

Alternatively, if you want to have it more balanced: (!?\[[^\]]+\])\(\<?([^>)]+)\>?\) + gm + $1(<$2>) .

Or even: !?\[([^\]]+)\]\(\<?([^>)]+)\>?\) + gm + ![$1](<$2>) .

As you can see, there is no one way to skin the cat. :wink: I have added a ? after the ! just to be on the safe side regarding non-image linking, i.e., normal MD links.

The regex does cover only one level. In the third example, only the inner MD link (the link text portion) is handled, and the outer one is left untouched. I leave it to you as an exercise.

[Pasted image 20230917184634.png](Pasted image 20230917184634.png "This is a title")

![Pasted image 20230917184634.png](Pasted image 20230917184634.png "This is a title")

[![Pasted image 20230917184634.png](Pasted image 20230917184634.png)](Pasted image 20230917184634.png "This is a title")

The rabbit hole is deep!

The approach is threefold and seems to be working fine – at least for now and still only for one level:

  • %20 + gm + SPACE: removes the URI encoding
  • \]\((.+?\.(png|jpg)).*?\.(png|jpg)([^)]*)\) + gm + ]($1$4): removes the old “duplicate” partial file name – Obsidian bug when renaming the target
  • (!?\[[^\]]+\])\(\<?([^>")]+)\>?( +("[^"]*"))?\) + gm + $1(<$2>$3): adds the <> and correctly handles a link title


This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.