FIX: Disable previews if diffhtml is enabled (#14537)

FIX: Disable previews if diffhtml is enabled (#14537)

diffhtml should not rerender video and audio elements so there is no point in having these.

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 7235b61..addf443 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
@@ -183,7 +183,10 @@ function renderImageOrPlayableMedia(tokens, idx, options, env, slf) {
   // see https://github.com/markdown-it/markdown-it/blob/master/docs/architecture.md#renderer
   // handles |video and |audio alt transformations for image tags
   if (split[1] === "video") {
-    if (options.discourse.previewing) {
+    if (
+      options.discourse.previewing &&
+      !options.discourse.limitedSiteSettings.enableDiffhtmlPreview
+    ) {
       return `<div class="onebox-placeholder-container">
         <span class="placeholder-icon video"></span>
       </div>`;
@@ -365,6 +368,7 @@ export function setup(opts, siteSettings, state) {
 
   opts.discourse.limitedSiteSettings = {
     secureMedia: siteSettings.secure_media,
+    enableDiffhtmlPreview: siteSettings.enable_diffhtml_preview,
   };
 
   opts.engine = window.markdownit({
diff --git a/lib/onebox/engine/allowlisted_generic_onebox.rb b/lib/onebox/engine/allowlisted_generic_onebox.rb
index 0ccc8eb..0bb2d72 100644
--- a/lib/onebox/engine/allowlisted_generic_onebox.rb
+++ b/lib/onebox/engine/allowlisted_generic_onebox.rb
@@ -65,8 +65,8 @@ module Onebox
       def placeholder_html
         return article_html if (is_article? || force_article_html?)
         return image_html if is_image?
-        return Onebox::Helpers.video_placeholder_html if is_video? || is_card?
-        return Onebox::Helpers.generic_placeholder_html if is_embedded?
+        return Onebox::Helpers.video_placeholder_html if !SiteSetting.enable_diffhtml_preview? && (is_video? || is_card?)
+        return Onebox::Helpers.generic_placeholder_html if !SiteSetting.enable_diffhtml_preview? && is_embedded?
         to_html
       end
 
diff --git a/lib/onebox/engine/audio_onebox.rb b/lib/onebox/engine/audio_onebox.rb
index 1ac09ce..8a5f52c 100644
--- a/lib/onebox/engine/audio_onebox.rb
+++ b/lib/onebox/engine/audio_onebox.rb
@@ -23,7 +23,7 @@ module Onebox
       end
 
       def placeholder_html
-        ::Onebox::Helpers.audio_placeholder_html
+        SiteSetting.enable_diffhtml_preview ? to_html : ::Onebox::Helpers.audio_placeholder_html
       end
     end
   end
diff --git a/lib/onebox/engine/video_onebox.rb b/lib/onebox/engine/video_onebox.rb
index 1fd6054..7d6c282 100644
--- a/lib/onebox/engine/video_onebox.rb
+++ b/lib/onebox/engine/video_onebox.rb
@@ -29,7 +29,7 @@ module Onebox
       end
 
       def placeholder_html
-        ::Onebox::Helpers.video_placeholder_html
+        SiteSetting.enable_diffhtml_preview ? to_html : ::Onebox::Helpers.video_placeholder_html
       end
     end
   end

GitHub sha: ba81d1853b7c4f0d6ee7d47e90bca2a30f2566fd

This commit appears in #14537 which was approved by eviltrout. It was merged by nbianca.