diff --git a/app/assets/javascripts/pretty-text/addon/engines/discourse-markdown-it.js b/app/assets/javascripts/pretty-text/addon/engines/discourse-markdown-it.js index c806dc0ffde..84f8ce8c37a 100644 --- a/app/assets/javascripts/pretty-text/addon/engines/discourse-markdown-it.js +++ b/app/assets/javascripts/pretty-text/addon/engines/discourse-markdown-it.js @@ -423,6 +423,7 @@ function unhoistForCooked(hoisted, cooked) { found = true; return hoisted[key]; }); + delete hoisted[key]; }; while (found) { @@ -578,14 +579,16 @@ export function setup(opts, siteSettings, state) { export function cook(raw, opts) { // we still have to hoist html_raw nodes so they bypass the allowlister - // this is the case for oneboxes - let hoisted = {}; - opts.discourse.hoisted = hoisted; + // this is the case for oneboxes and also certain plugins that require + // raw HTML rendering within markdown bbcode rules + opts.discourse.hoisted ??= {}; const rendered = opts.engine.render(raw); let cooked = opts.discourse.sanitizer(rendered).trim(); - cooked = unhoistForCooked(hoisted, cooked); - delete opts.discourse.hoisted; + + // opts.discourse.hoisted guid keys will be deleted within here to + // keep the object empty + cooked = unhoistForCooked(opts.discourse.hoisted, cooked); return cooked; } diff --git a/plugins/chat/spec/integration/post_chat_quote_spec.rb b/plugins/chat/spec/integration/post_chat_quote_spec.rb index 1c1e0430bd5..51d5c327cfe 100644 --- a/plugins/chat/spec/integration/post_chat_quote_spec.rb +++ b/plugins/chat/spec/integration/post_chat_quote_spec.rb @@ -211,4 +211,52 @@ martin ensure InlineOneboxer.invalidate("https://en.wikipedia.org/wiki/Hyperlink") end + + it "handles nested chat transcripts in posts" do + SiteSetting.external_system_avatars_enabled = false + freeze_time + + channel = Fabricate(:chat_channel) + message1 = Fabricate(:chat_message, chat_channel: channel, user: post.user) + message2 = Fabricate(:chat_message, chat_channel: channel, user: post.user) + md = ChatTranscriptService.new(channel, message2.user, messages_or_ids: [message2.id]).generate_markdown + message1.update!(message: md) + md_for_post = ChatTranscriptService.new(channel, message1.user, messages_or_ids: [message1.id]).generate_markdown + post.update!(raw: md_for_post) + expect(post.cooked.chomp).to eq(<<~COOKED.chomp) +