DEV: Add logging for stack level too deep exception in HtmlToMarkdown

This commit is contained in:
Daniel Waterworth 2020-07-09 12:22:03 +01:00
parent e0713455ca
commit 4a9ee25c56
1 changed files with 11 additions and 2 deletions

View File

@ -6,21 +6,30 @@ require "securerandom"
class HtmlToMarkdown
def initialize(html, opts = {})
@html = html
@opts = opts
# we're only interested in <body>
@doc = Nokogiri::HTML5(html).at("body")
end
def to_markdown
remove_not_allowed!(@doc)
remove_hidden!(@doc)
hoist_line_breaks!(@doc)
remove_whitespaces!(@doc)
end
def to_markdown
traverse(@doc)
.gsub(/\n{2,}/, "\n\n")
.strip
rescue SystemStackError => e
Discourse.warn_exception(
e,
message: "stack level too deep in HtmlToMarkdown",
env: { html: @html },
)
raise
end
private