]> cat aescling's git repositories - mastodon.git/commit
Use a tree‐based approach for adv. text formatting
authorkibigo! <go@kibi.family>
Wed, 9 Nov 2022 04:59:07 +0000 (20:59 -0800)
committerkibigo! <go@kibi.family>
Fri, 11 Nov 2022 10:11:12 +0000 (02:11 -0800)
commit03d0e909d06da0e4e8a0a4d504775b4825749b3c
tree4a51a4dcf18a00fb8ae18b37f53d11248b692ede
parente846ec516e26f5938004f8bfdf0b98944930103e
Use a tree‐based approach for adv. text formatting

Sanitizing HTML/Markdown means parsing the content into an HTML tree
under‐the‐hood anyway, and it is more accurate to do mention/hashtag
replacement on the text nodes in that tree than it is to try to hack it
in with regexes et cetera.

This undoes the overrides of `#entities` and `#rewrite` on
`AdvancedTextFormatter` but also stops using them, instead keeping
track of the parsed Nokogiri tree itself and using that in the `#to_s`
method.

Internally, this tree uses `<mastodon-entity>` nodes to keep track of
hashtags, links, and mentions. Sanitization is moved to the beginning,
so it should be known that these do not appear in the input.
app/lib/advanced_text_formatter.rb