[openstreetmap/openstreetmap-website] Provide a truncated view of recent diaries (PR #5121)
Tom Hughes
notifications at github.com
Tue Nov 19 18:48:32 UTC 2024
@tomhughes commented on this pull request.
I wonder about the overall approach of doing this in a concern - would it be better to do it in `RichText::Base` perhaps?
What I envisage is a new method there to do truncation and then altering the `to_html` methods in the derived classes to take an optional truncation length (defaulting to `nil`) and apply the truncation method to their result if it's set - then instead of a boolean parameter the views can pass in a truncation length.
Just a thought, but it seems with the current implementation things get messy when trying to deal with the order things are being done and what is and isn't sanitised etc.
> + if accumulated_length >= max_length
+ node.remove unless !last_child.nil? && last_child.ancestors.include?(node)
+ next
+ end
+
+ next unless node.children.empty?
+
+ accumulated_length += node.text? ? node.text.length : empty_tag_length
+ if accumulated_length < max_length
+ last_child = node
+ else
+ node.remove
+ end
+ end
+
+ RichText::SimpleFormat.new.sanitize(doc)
Why are we running sanitize here? The HTML was already sanitised before this was called, at least in the current use of this concern?
--
Reply to this email directly or view it on GitHub:
https://github.com/openstreetmap/openstreetmap-website/pull/5121#pullrequestreview-2446310041
You are receiving this because you are subscribed to this thread.
Message ID: <openstreetmap/openstreetmap-website/pull/5121/review/2446310041 at github.com>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.openstreetmap.org/pipermail/rails-dev/attachments/20241119/c11dadad/attachment.htm>
More information about the rails-dev
mailing list