Change text extraction in PlainTextFormatter
to be faster (#26727)
This commit is contained in:
parent
ce75c175cd
commit
2e0eab9d18
1 changed files with 5 additions and 4 deletions
|
@ -1,9 +1,7 @@
|
||||||
# frozen_string_literal: true
|
# frozen_string_literal: true
|
||||||
|
|
||||||
class PlainTextFormatter
|
class PlainTextFormatter
|
||||||
include ActionView::Helpers::TextHelper
|
NEWLINE_TAGS_RE = %r{(<br />|<br>|</p>)+}
|
||||||
|
|
||||||
NEWLINE_TAGS_RE = /(<br \/>|<br>|<\/p>)+/.freeze
|
|
||||||
|
|
||||||
attr_reader :text, :local
|
attr_reader :text, :local
|
||||||
|
|
||||||
|
@ -18,7 +16,10 @@ class PlainTextFormatter
|
||||||
if local?
|
if local?
|
||||||
text
|
text
|
||||||
else
|
else
|
||||||
strip_tags(insert_newlines).chomp
|
node = Nokogiri::HTML.fragment(insert_newlines)
|
||||||
|
# Elements that are entirely removed with our Sanitize config
|
||||||
|
node.xpath('.//iframe|.//math|.//noembed|.//noframes|.//noscript|.//plaintext|.//script|.//style|.//svg|.//xmp').remove
|
||||||
|
node.text.chomp
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue