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
…68721)


Co-authored-by: Mamaduka <[email protected]>
Co-authored-by: t-hamano <[email protected]>
Co-authored-by: ZebulanStanphill <[email protected]>
Co-authored-by: kathrynwp <[email protected]>
Co-authored-by: ndiego <[email protected]>
Co-authored-by: jorgefilipecosta <[email protected]>
Co-authored-by: petitphp <[email protected]>
Co-authored-by: ts-mz <[email protected]>
  • Loading branch information
9 people authored Jan 18, 2025
1 parent bd2c328 commit 61d7b50
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

1 comment on commit 61d7b50

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Flaky tests detected in 61d7b50.
Some tests passed with failed attempts. The failures may not be related to this commit but are still reported for visibility. See the documentation for more information.

🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/12842165664
📝 Reported issues:

Please sign in to comment.