element-web: Can't escape > at the start of message with \ in the new composer
Description
The old composer sent \>hello as >hello, but now it sends \>hello.
Version information
- Platform: web
For the web app:
- Browser: Firefox
- URL: self-hosted
1.5.0
About this issue
- Original URL
- State: closed
- Created 5 years ago
- Reactions: 6
- Comments: 16 (7 by maintainers)
While having /plain as an option is fine when you plan on avoiding markdown in multiple places, having \ as an option to escape a single instance would be more efficient, and is used in other applications for that reason
Markdown parsing seems quite odd/inconsistent now. Looks like backslash escapes only work if unescaped markdown is used elsewhere in the same message?
This makes it different from every other markdown/commonmark implementation I’ve ever seen, and having to use
/plainspecifically for the case where no other markdown is used, rather than the standard escape sequences that should work everywhere, feels very inconsistent to me.renders
Which is fine.
renders
which is weird.
renders
which is weird.
Since the old markdown parser has been removed completely, there is no longer any straightforward workaround. As before, requiring
/plainin these cases is weird.So there’s a few things:
It boils down to the serialisation not performing a Markdown-to-HTML conversion if it thinks the message is plaintext: https://github.com/matrix-org/matrix-react-sdk/blob/6f6d6b096a0e752f0ad649d70cd541008334c634/src/editor/serialize.js#L38-L44
Unfortunately,
.isPlainText()relies on the CommonMark node type oftextas seen in: https://github.com/matrix-org/matrix-react-sdk/blob/6f6d6b096a0e752f0ad649d70cd541008334c634/src/Markdown.js#L71-L92The problem is CommonMark describes nodes as
textafter parsing escapes. It thinks\*test\*is*test*and a text node. Which is correct: the post-parse node is unformatted text. Unfortunately, Riot then takes that to mean the pre-parse input should be displayed as-is, which is incorrect.I think this looks like just an optimisation, and the easy fix would be to disable the optimisation by not using
.isPlainText()at all. Anything that goes through the Markdown path should always use.toHTML()or similar to get the post-parse output. This would not affect/plainas it does not go down this code path at all.