diff --git a/lib/pretty_text.rb b/lib/pretty_text.rb index 2c4622815..81846f75e 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