diff --git a/assets/css/src/amp-default.css b/assets/css/src/amp-default.css index e8aae6e8712..558ffde7d84 100644 --- a/assets/css/src/amp-default.css +++ b/assets/css/src/amp-default.css @@ -61,3 +61,19 @@ body amp-audio:not([controls]) { .amp-wp-default-form-message[submit-success] > p:empty { display: none; } + +amp-carousel .amp-wp-gallery-caption { + position: absolute; + bottom: 0; + left: 0; + right: 0; + text-align: center; + background-color: rgba(0, 0, 0, 0.5); + color: #fff; + padding: 1rem; +} + +.wp-block-gallery[data-amp-carousel="true"] { + display: block; + flex-wrap: unset; +} diff --git a/includes/sanitizers/class-amp-gallery-block-sanitizer.php b/includes/sanitizers/class-amp-gallery-block-sanitizer.php index 84a4c7f0f90..25779386fb6 100644 --- a/includes/sanitizers/class-amp-gallery-block-sanitizer.php +++ b/includes/sanitizers/class-amp-gallery-block-sanitizer.php @@ -73,23 +73,44 @@ class AMP_Gallery_Block_Sanitizer extends AMP_Base_Sanitizer { * @since 0.2 */ public function sanitize() { - $nodes = $this->dom->getElementsByTagName( self::$tag ); - $num_nodes = $nodes->length; - if ( 0 === $num_nodes ) { - return; + $xpath = new DOMXPath( $this->dom ); + $class_query = 'contains( concat( " ", normalize-space( @class ), " " ), " wp-block-gallery " )'; + $expr = sprintf( + '//ul[ %s ]', + implode( + ' or ', + [ + sprintf( '( parent::figure[ %s ] )', $class_query ), + $class_query, + ] + ) + ); + $query = $xpath->query( $expr ); + + $nodes = []; + foreach ( $query as $node ) { + $nodes[] = $node; } - for ( $i = $num_nodes - 1; $i >= 0; $i-- ) { - $node = $nodes->item( $i ); + foreach ( $nodes as $node ) { + /** + * Element + * + * @var DOMElement $node + */ - // We're looking for