Skip to content

Commit fdbf30f

Browse files
committed
only process video shortcode for non-Gutenberg posts, and keep start and end video tags for Gutenberg posts
1 parent 11bbe68 commit fdbf30f

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

wordpress-shortcodes/src/main/java/org/wordpress/aztec/plugins/shortcodes/VideoShortcodePlugin.kt

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package org.wordpress.aztec.plugins.shortcodes
33
import org.wordpress.aztec.plugins.shortcodes.extensions.ATTRIBUTE_VIDEOPRESS_HIDDEN_ID
44
import org.wordpress.aztec.plugins.shortcodes.extensions.ATTRIBUTE_VIDEOPRESS_HIDDEN_SRC
55
import org.wordpress.aztec.plugins.html2visual.IHtmlPreprocessor
6+
import org.wordpress.aztec.plugins.shortcodes.utils.GutenbergUtils
67
import org.wordpress.aztec.plugins.visual2html.IHtmlPostprocessor
78

89
class VideoShortcodePlugin : IHtmlPreprocessor, IHtmlPostprocessor {
@@ -11,12 +12,20 @@ class VideoShortcodePlugin : IHtmlPreprocessor, IHtmlPostprocessor {
1112
private val TAG_VIDEOPRESS_SHORTCODE = "wpvideo"
1213

1314
override fun beforeHtmlProcessed(source: String): String {
15+
if (GutenbergUtils.contentContainsGutenbergBlocks(source)) return source
1416
var newSource = source.replace(Regex("(?<!\\[)\\[$TAG([^\\]]*)\\](?!\\])"), "<$TAG$1 />")
1517
newSource = newSource.replace(Regex("(?<!\\[)\\[$TAG_VIDEOPRESS_SHORTCODE([^\\]]*)\\](?!\\])"), { it -> fromVideoPressShortCodeToHTML(it) })
1618
return newSource
1719
}
1820

1921
override fun onHtmlProcessed(source: String): String {
22+
if (GutenbergUtils.contentContainsGutenbergBlocks(source)) {
23+
// From https://developer.mozilla.org/en-US/docs/Web/HTML/Element/video
24+
// > Tag omission None, both the starting and ending tag are mandatory.
25+
return StringBuilder(source)
26+
.replace(Regex("(<$TAG[^>]*?)(\\s*/>)"), "\$1></$TAG>")
27+
}
28+
2029
return StringBuilder(source)
2130
.replace(Regex("<$TAG([^>]*(?<! )) */>"), { it -> fromHTMLToShortcode(it) })
2231
.replace(Regex("<$TAG([^>]*(?<! )) */>"), { it -> fromHTMLToShortcode(it) })

0 commit comments

Comments
 (0)