coffeebank / coffee-maubot

Matrix bot plugins for Maubot 🍢 Add link previews, choose, and other tools to your Matrix chat ☕
https://coffeebank.github.io/coffee-maubot
11 stars 5 forks source link

urlpreview: Don't fetch previews for URLs in code blocks #5

Open peterrus opened 1 year ago

peterrus commented 1 year ago

When someone embeds an URL in a code block (backtick or triple backtick) we probably shouldn't try to fetch a preview because that URL is there for different purposes than a regular URL that is posted to a channel.

I tried to do this with a regex, but my regex wizardry doesn't cut it unfortunately.

coffeebank commented 1 year ago

Thinking a possible way is to run two Regex commands:

  1. The first one remains the same, parsing all instances of https://
  2. The second one parses for all instances of (`|```) ... https:// ... (`|```) and returning the urls

Then, for every Regex 1 result, if result is in Regex 2, we ignore it

Downsides: Very inefficient, fails if users use ` as a regular quote, relies on parsing ` specifically (and not \<pre> \<code> etc.)

peterrus commented 1 year ago

Yeah this one seems quite hard. Maybe someone comes along with a good idea!