From a79b1807d79ec16e37a69a4ca0e54a85f90389a9 Mon Sep 17 00:00:00 2001 From: Sam Date: Fri, 14 Nov 2014 17:51:04 +1100 Subject: [PATCH] FEATURE: attempt to recover from corrupt markdown engine --- lib/pretty_text.rb | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/lib/pretty_text.rb b/lib/pretty_text.rb index 2c4622815c6..81846f75e7a 100644 --- a/lib/pretty_text.rb +++ b/lib/pretty_text.rb @@ -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