mirror of
https://github.com/discourse/discourse.git
synced 2025-05-22 07:53:49 +08:00
DEV: Add logging for stack level too deep exception in HtmlToMarkdown
This commit is contained in:
@ -6,21 +6,30 @@ require "securerandom"
|
|||||||
class HtmlToMarkdown
|
class HtmlToMarkdown
|
||||||
|
|
||||||
def initialize(html, opts = {})
|
def initialize(html, opts = {})
|
||||||
|
@html = html
|
||||||
@opts = opts
|
@opts = opts
|
||||||
|
|
||||||
# we're only interested in <body>
|
# we're only interested in <body>
|
||||||
@doc = Nokogiri::HTML5(html).at("body")
|
@doc = Nokogiri::HTML5(html).at("body")
|
||||||
|
end
|
||||||
|
|
||||||
|
def to_markdown
|
||||||
remove_not_allowed!(@doc)
|
remove_not_allowed!(@doc)
|
||||||
remove_hidden!(@doc)
|
remove_hidden!(@doc)
|
||||||
hoist_line_breaks!(@doc)
|
hoist_line_breaks!(@doc)
|
||||||
remove_whitespaces!(@doc)
|
remove_whitespaces!(@doc)
|
||||||
end
|
|
||||||
|
|
||||||
def to_markdown
|
|
||||||
traverse(@doc)
|
traverse(@doc)
|
||||||
.gsub(/\n{2,}/, "\n\n")
|
.gsub(/\n{2,}/, "\n\n")
|
||||||
.strip
|
.strip
|
||||||
|
rescue SystemStackError => e
|
||||||
|
Discourse.warn_exception(
|
||||||
|
e,
|
||||||
|
message: "stack level too deep in HtmlToMarkdown",
|
||||||
|
env: { html: @html },
|
||||||
|
)
|
||||||
|
|
||||||
|
raise
|
||||||
end
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
Reference in New Issue
Block a user