Chatwoot/app/presenters/html_parser.rb
Tejaswini Chile 1467a8fa33
Fix: parse verification mail (#3864)
Email parsing logic was stripping of HTML tables which was causing the issue in this case.

Fixes: #3731
2022-01-27 15:45:26 -08:00

30 lines
532 B
Ruby

class HtmlParser
def self.parse_reply(raw_body)
new(raw_body).filtered_text
end
attr_reader :raw_body
def initialize(raw_body)
@raw_body = raw_body
end
def document
@document ||= Nokogiri::HTML(raw_body)
end
def filter_replies!
document.xpath('//blockquote').each { |n| n.replace('> ') }
end
def filtered_html
@filtered_html ||= begin
filter_replies!
document.inner_html
end
end
def filtered_text
@filtered_text ||= Html2Text.convert(filtered_html)
end
end