How to escape tags in Web Clipper while preserving markdown headings?

What I’m trying to do

I’m looking for a filter to use in Obsidian’s Web Clipper extension that escapes tags while preserving markdown headings. Here’s an example.

Original:

text

# Heading 1
Some text with #tag and another #example_tag.
## Subheading

Result after replacement:

text

# Heading 1
Some text with \#tag and another \#example_tag.
## Subheading

Things I have tried

Here’s my current query based on this reddit thread:

{{content|replace:("\#":"\\\#")}}

Unfortunately, this seems to also escape the “#” symbol in markdown headings.

Thanks for your help!

I think Web Clipper does match replacement strings. You could give this a try:

{{content|replace:"/(#[^ \#])/g":"\\$1"}}

This works! Thank you so much!!!

1 Like