Skip to content

Commit

Permalink
Quote: fix raw transform handler (#43093)
Browse files Browse the repository at this point in the history
  • Loading branch information
ellatrix authored Aug 10, 2022
1 parent 8568104 commit 626cb0d
Show file tree
Hide file tree
Showing 7 changed files with 17 additions and 12 deletions.
10 changes: 3 additions & 7 deletions packages/block-library/src/quote/transforms.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
/**
* WordPress dependencies
*/
import {
createBlock,
parseWithAttributeSchema,
rawHandler,
} from '@wordpress/blocks';
import { createBlock, parseWithAttributeSchema } from '@wordpress/blocks';

const transforms = {
from: [
Expand Down Expand Up @@ -59,7 +55,7 @@ const transforms = {
},
} ),
selector: 'blockquote',
transform: ( node ) => {
transform: ( node, handler ) => {
return createBlock(
'core/quote',
// Don't try to parse any `cite` out of this content.
Expand All @@ -68,7 +64,7 @@ const transforms = {
// * If the cite is nested in the quoted text, it's wrong to
// remove it.
{},
rawHandler( {
handler( {
HTML: node.innerHTML,
mode: 'BLOCKS',
} )
Expand Down
8 changes: 5 additions & 3 deletions packages/blocks/src/api/raw-handling/html-to-blocks.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,13 @@ import { getRawTransforms } from './get-raw-transforms';
* top-level tag. The HTML should be filtered to not have any text between
* top-level tags and formatted in a way that blocks can handle the HTML.
*
* @param {string} html HTML to convert.
* @param {string} html HTML to convert.
* @param {Function} handler The handler calling htmlToBlocks: either rawHandler
* or pasteHandler.
*
* @return {Array} An array of blocks.
*/
export function htmlToBlocks( html ) {
export function htmlToBlocks( html, handler ) {
const doc = document.implementation.createHTMLDocument( '' );

doc.body.innerHTML = html;
Expand All @@ -36,7 +38,7 @@ export function htmlToBlocks( html ) {
const { transform, blockName } = rawTransform;

if ( transform ) {
return transform( node );
return transform( node, handler );
}

return createBlock(
Expand Down
2 changes: 1 addition & 1 deletion packages/blocks/src/api/raw-handling/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ export function rawHandler( { HTML = '' } ) {
piece = deepFilterHTML( piece, filters, blockContentSchema );
piece = normaliseBlocks( piece );

return htmlToBlocks( piece );
return htmlToBlocks( piece, rawHandler );
} )
.flat()
.filter( Boolean );
Expand Down
2 changes: 1 addition & 1 deletion packages/blocks/src/api/raw-handling/paste-handler.js
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ export function pasteHandler( {
// Allows us to ask for this information when we get a report.
console.log( 'Processed HTML piece:\n\n', piece );

return htmlToBlocks( piece );
return htmlToBlocks( piece, pasteHandler );
} )
.flat()
.filter( Boolean );
Expand Down
1 change: 1 addition & 0 deletions test/integration/blocks-raw-handling.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -345,6 +345,7 @@ describe( 'Blocks raw handling', () => {
'wordpress',
'gutenberg',
'shortcode-matching',
'slack-quote',
].forEach( ( type ) => {
// eslint-disable-next-line jest/valid-title
it( type, () => {
Expand Down
1 change: 1 addition & 0 deletions test/integration/fixtures/documents/slack-quote-in.html
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<blockquote type="cite" class="c-mrkdwn__quote" data-stringify-type="quote" style="box-sizing: inherit; margin: 4px 0px; padding: 0px 0px 0px 16px; position: relative; counter-reset: list-0 0 list-1 0 list-2 0 list-3 0 list-4 0 list-5 0 list-6 0 list-7 0 list-8 0 list-9 0; color: rgb(209, 210, 211); font-family: Slack-Lato, Slack-Fractions, appleLogo, sans-serif; font-size: 15px; font-style: normal; font-variant-ligatures: common-ligatures; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: left; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; background-color: rgb(34, 37, 41); text-decoration-thickness: initial; text-decoration-style: initial; text-decoration-color: initial;">Test with<span> </span><a target="_blank" class="c-link" data-stringify-link="http://w.org" delay="150" data-sk="tooltip_parent" href="http://w.org/" rel="noopener noreferrer" tabindex="-1" data-remove-tab-index="true" style="box-sizing: inherit; color: rgba(var(--sk_highlight,18,100,163),1); text-decoration: none;">link</a>.</blockquote>
5 changes: 5 additions & 0 deletions test/integration/fixtures/documents/slack-quote-out.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<!-- wp:quote -->
<blockquote class="wp-block-quote"><!-- wp:paragraph -->
<p>Test with&nbsp;<a target="_blank" href="http://w.org/" rel="noreferrer noopener">link</a>.</p>
<!-- /wp:paragraph --></blockquote>
<!-- /wp:quote -->

0 comments on commit 626cb0d

Please sign in to comment.