Don't guess mentions from text within code blocks #78

Open
opened 2026-03-07 09:34:12 +00:00 by cadence · 0 comments
Owner

Currently guessed mentions are processed over the whole message by a regexp, but this has the problem that it also processes them inside markdown code blocks. They shouldn't be processed in code blocks because regular mentions wouldn't be processed there either.

It is not possible to parse the Markdown code block format with regex, so this would have to be done in a real parser. Possibilities:

  • Put it next to transformParsedVia, which also works over the parsed markdown AST but async functions can actually be called here.
    • Probably has the most potential but haven't looked through this thoroughly
  • Edit the @cloudrac3r/discord-markdown library to add another hook for something something plaintext (like autolink), or move the @mention guessing regexp into there and add a hook for the maximumWrittenSection.
    • Problem: Mentions need to be resolved async but discord markdown parser hooks are sync.
  • After creating Matrix content, re-parse as HTML and guess mentions in text that isn't contained within a code/pre block
    • Seems bad for performance, to say the least
  • Write a custom parser for these code blocks and run it on the discord text first, guess mentions, then pass the result to the main discord markdown parser
    • Seems bad for order of operations readability

Guessed mentions are also known as "scenario 3" in code.

Currently guessed mentions are processed over the whole message by a regexp, but this has the problem that it also processes them inside markdown code blocks. They shouldn't be processed in code blocks because regular mentions wouldn't be processed there either. It is not possible to parse the Markdown code block format with regex, so this would have to be done in a real parser. Possibilities: - Put it next to `transformParsedVia`, which also works over the parsed markdown AST but async functions can actually be called here. - Probably has the most potential but haven't looked through this thoroughly - Edit the `@cloudrac3r/discord-markdown` library to add another hook for something something plaintext (like autolink), or move the @mention guessing regexp into there and add a hook for the `maximumWrittenSection`. - Problem: Mentions need to be resolved async but discord markdown parser hooks are sync. - After creating Matrix content, re-parse as HTML and guess mentions in text that isn't contained within a code/pre block - Seems bad for performance, to say the least - Write a custom parser for these code blocks and run it on the discord text first, guess mentions, then pass the result to the main discord markdown parser - Seems bad for order of operations readability Guessed mentions are also known as "scenario 3" in code.
cadence added the
moderately approachable
label 2026-03-07 09:36:42 +00:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference: cadence/out-of-your-element#78
No description provided.