2016-11-10 06:24:02 +00:00
|
|
|
module Gitlab
|
|
|
|
module Email
|
|
|
|
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
|
2016-11-10 23:10:44 +00:00
|
|
|
@document ||= Nokogiri::HTML.parse(raw_body)
|
2016-11-10 06:24:02 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def filter_replies!
|
2016-11-11 04:38:36 +00:00
|
|
|
document.xpath('//blockquote').each(&:remove)
|
|
|
|
document.xpath('//table').each(&:remove)
|
2016-11-10 06:24:02 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def filtered_html
|
2016-11-10 08:40:53 +00:00
|
|
|
@filtered_html ||= begin
|
|
|
|
filter_replies!
|
|
|
|
document.inner_html
|
|
|
|
end
|
2016-11-10 06:24:02 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def filtered_text
|
|
|
|
@filtered_text ||= Html2Text.convert(filtered_html)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|