Copying source code from a site and pasting leads to escape characters


Go to
Write some code

const numArr: number[] = [1,2,3]

Copy and paste to Obsidian

In the result

const numArr: number\[\] \= \[1,2,3\]

This happens when you paste rich text (HTML). The Typescript playground does this probably to keep the syntax highlighting colors. This will then be converted to Markdown, and since square brackets have a special meaning in Markdown, they are escaped.

Interestingly, if you paste plain text, they are not escaped. And if you copy and paste from your own posting, then it will be pasted as a fenced code block.

Another issue here is that if you paste code into an existing code fence, it will be still escaped. Inside a code fence, everything should be better pasted in raw format only.

1 Like

use ctrl-shift-v to paste plain text.

Also this has been discussed before in the forum. Please, search!


Yes, this has been discussed, but I fear these questions will not stop, because as explained above, the behavior is not consistent. If you paste plain text with Ctrl-V (i.e. if there is only plain text in the clipboard), then square brackets will not be escaped, otherwise they are. This is not really intuitive for the ordinary user.


I have tried to search and found nothing. For macos users we need to press Shift + Command + Alt + v

1 Like

It seems that ctrl-shift-v is the suggested solution. I don’t think that this is acceptable though. I’ve been working with Obsidian for several months now and I paste using the regular ctrl v shortcut by accident multiple times every day. This makes it very frustrating to work with Obsidian. In my opinion the escaping is a bug and the ctrl-shift-v workaround is not really workable as a long term solution. As you can see this has been posted multiple times already, so there are quite a few users out there having this issue.

1 Like


You can enable and disable the feature of pasting formatted text with Ctrl-V with the “Auto convert HTML” option.

I would have preferred an third option, namely switching the meaning of Ctrl-V and Ctrl-Shift-V instead of disabling it.

Particularly since it seems that after disabling the feature, you cannot even copy formatted with the context menu.

I have created a new feature request for this here.

1 Like

@Cito, thanks that is HUGELY helpful. I wasn’t aware that this is something I can switch off. I can live without the HTML auto conversion but the copy past issue was driving me nuts.

That helped, thank you.

Thank you so much!
Now it finally works