From 4a9ee25c56a575bc2cd5b677371250e819c9508f Mon Sep 17 00:00:00 2001 From: Daniel Waterworth Date: Thu, 9 Jul 2020 12:22:03 +0100 Subject: [PATCH] DEV: Add logging for stack level too deep exception in HtmlToMarkdown --- lib/html_to_markdown.rb | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/lib/html_to_markdown.rb b/lib/html_to_markdown.rb index d2fb51f34c8..fc36861a4be 100644 --- a/lib/html_to_markdown.rb +++ b/lib/html_to_markdown.rb @@ -6,21 +6,30 @@ require "securerandom" class HtmlToMarkdown def initialize(html, opts = {}) + @html = html @opts = opts # we're only interested in @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