FEATURE: attempt to recover from corrupt markdown engine

This commit is contained in:
Sam 2014-11-14 17:51:04 +11:00
parent c7bc692f40
commit a79b1807d7
1 changed files with 19 additions and 0 deletions

View File

@ -116,6 +116,12 @@ module PrettyText
@ctx
end
def self.reset_context
@ctx_init.synchronize do
@ctx = nil
end
end
def self.decorate_context(context)
context.eval("Discourse.SiteSettings = #{SiteSetting.client_settings_json};")
context.eval("Discourse.CDN = '#{Rails.configuration.action_controller.asset_host}';")
@ -151,6 +157,19 @@ module PrettyText
baked = context.eval('Discourse.Markdown.markdownConverter(opts).makeHtml(raw)')
end
if baked.blank? && !(opts || {})[:skip_blank_test]
# we may have a js engine issue
test = markdown("a", skip_blank_test: true)
if test.blank?
Rails.logger.warn("Markdown engine appears to have crashed, resetting context")
reset_context
opts ||= {}
opts = opts.dup
opts[:skip_blank_test] = true
baked = markdown(text, opts)
end
end
baked
end