]> cat aescling's git repositories - mastodon.git/commitdiff
Give internal `<mastodon-entity>`s contents
authorkibigo! <go@kibi.family>
Fri, 11 Nov 2022 23:49:00 +0000 (15:49 -0800)
committerkibigo! <go@kibi.family>
Sun, 13 Nov 2022 04:50:44 +0000 (20:50 -0800)
These aren’t used by the entity formatter, but they provide a better
fallback behaviour if the entity is ever stripped prior to formatting
(for example, because it is used inside of an inline spoiler).

app/lib/advanced_text_formatter.rb

index c8c6e1d01f150435cc7e480119b00c13bd21fdb0..bcbe3f5d9cade18773f94d2dd616a1ed1f02f6b1 100644 (file)
@@ -81,7 +81,9 @@ class AdvancedTextFormatter < TextFormatter
           extract_url_without_protocol: false
         ) do |entity|
           # Iterate over entities in this text node.
-          advance = entity[:indices].first - processed_index
+          entity_start = entity[:indices].first
+          entity_end = entity[:indices].last
+          advance = entity_start - processed_index
           if advance.positive?
             # Text node for content which precedes entity.
             replacement << Nokogiri::XML::Text.new(
@@ -100,8 +102,12 @@ class AdvancedTextFormatter < TextFormatter
             elt['kind'] = 'mention'
             elt['value'] = entity[:screen_name]
           end
+          elt << Nokogiri::XML::Text.new(
+            content[entity_start, entity_end - entity_start],
+            document
+          )
           replacement << elt
-          processed_index = entity[:indices].last
+          processed_index = entity_end
         end
         if processed_index < content.size
           # Text node for remaining content.