Skip to content

Commit

Permalink
Embed: Remove aspect ratio classes when transforming into Paragraph
Browse files Browse the repository at this point in the history
  • Loading branch information
Mamaduka committed Jan 16, 2025
1 parent ba9f079 commit b474d6f
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
3 changes: 2 additions & 1 deletion packages/block-editor/src/hooks/custom-class-name.js
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,8 @@ export function addTransforms( result, source, index, results ) {
// if source N does not exists we do nothing.
if ( source[ index ] ) {
const originClassName = source[ index ]?.attributes.className;
if ( originClassName ) {
// Avoid overriding classes if the transformed block already includes them.
if ( originClassName && result.attributes.className === undefined ) {
return {
...result,
attributes: {
Expand Down
4 changes: 3 additions & 1 deletion packages/block-library/src/embed/transforms.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { createBlock } from '@wordpress/blocks';
* Internal dependencies
*/
import metadata from './block.json';
import { removeAspectRatioClasses } from './util';

const { name: EMBED_BLOCK } = metadata;

Expand All @@ -33,13 +34,14 @@ const transforms = {
type: 'block',
blocks: [ 'core/paragraph' ],
isMatch: ( { url } ) => !! url,
transform: ( { url, caption } ) => {
transform: ( { url, caption, className } ) => {
let value = `<a href="${ url }">${ url }</a>`;
if ( caption?.trim() ) {
value += `<br />${ caption }`;
}
return createBlock( 'core/paragraph', {
content: value,
className: removeAspectRatioClasses( className ),
} );
},
},
Expand Down

0 comments on commit b474d6f

Please sign in to comment.