@AntonKhorev commented on this pull request.
> @@ -65,6 +65,32 @@ def description
protected
+ def truncate_html(html_doc, max_length = nil, empty_tag_length = 1000)
+ return html_doc if max_length.nil?
+
+ doc = Nokogiri::HTML::DocumentFragment.parse(html_doc)
+ accumulated_length = 0
+ last_child = nil
+
+ doc.traverse do |node|
My idea was that there are some types of elements that you either completely
keep or completely discard. A paragraph would be one of them. Here instead a
paragraph may get truncated after after any of elements inside it. Let's say
you have a link, any if that link happens to go over the truncation threshold,
the rest of the paragraph gets thrown out. That can make it unreadable.
This is even more true for tables. Truncation as implemented here can stop in
the middle of some cell. It won't try to complete a row, although completing a
row wouldn't work in general. Tables probably also need to be either entirely
in or entirely out. Something like `<div>` or `<section>`, that can be included
partially.
--
Reply to this email directly or view it on GitHub:
https://github.com/openstreetmap/openstreetmap-website/pull/5121#pullrequestreview-2577898800
You are receiving this because you are subscribed to this thread.
Message ID:
<openstreetmap/openstreetmap-website/pull/5121/review/2577898...@github.com>
_______________________________________________
rails-dev mailing list
rails-dev@openstreetmap.org
https://lists.openstreetmap.org/listinfo/rails-dev