From 3b207691fc70251d70ff2b872f853c58a9c27b5c Mon Sep 17 00:00:00 2001 From: Ella Date: Mon, 18 Dec 2023 22:58:11 +0200 Subject: [PATCH] Fix raw matcher --- packages/blocks/README.md | 1 + packages/blocks/src/api/parser/get-block-attributes.js | 8 ++++---- packages/blocks/src/api/parser/index.js | 5 +++-- 3 files changed, 8 insertions(+), 6 deletions(-) diff --git a/packages/blocks/README.md b/packages/blocks/README.md index 8e6fdc9d900dbb..78531f54b8cc94 100644 --- a/packages/blocks/README.md +++ b/packages/blocks/README.md @@ -97,6 +97,7 @@ _Parameters_ - _blockTypeOrName_ `string|Object`: Block type or name. - _innerHTML_ `string|Node`: Raw block content. - _attributes_ `?Object`: Known block attributes (from delimiters). +- _innerDom_ `?Node`: Raw block content parsed into DOM. _Returns_ diff --git a/packages/blocks/src/api/parser/get-block-attributes.js b/packages/blocks/src/api/parser/get-block-attributes.js index 3c9604f6197924..cc15d5c21efac1 100644 --- a/packages/blocks/src/api/parser/get-block-attributes.js +++ b/packages/blocks/src/api/parser/get-block-attributes.js @@ -286,16 +286,16 @@ export function parseWithAttributeSchema( innerHTML, attributeSchema ) { * @param {string|Object} blockTypeOrName Block type or name. * @param {string|Node} innerHTML Raw block content. * @param {?Object} attributes Known block attributes (from delimiters). - * + * @param {?Node} innerDom Raw block content parsed into DOM. * @return {Object} All block attributes. */ export function getBlockAttributes( blockTypeOrName, innerHTML, - attributes = {} + attributes = {}, + innerDom ) { - const doc = - typeof innerHTML === 'string' ? parseHtml( innerHTML ) : innerHTML; + const doc = innerDom ? innerDom : parseHtml( innerHTML ); const blockType = normalizeBlockType( blockTypeOrName ); const blockAttributes = Object.fromEntries( diff --git a/packages/blocks/src/api/parser/index.js b/packages/blocks/src/api/parser/index.js index 704c45a4a001c6..b2251a38f2d8cf 100644 --- a/packages/blocks/src/api/parser/index.js +++ b/packages/blocks/src/api/parser/index.js @@ -233,8 +233,9 @@ export function parseRawBlock( rawBlock, options ) { normalizedBlock.blockName, getBlockAttributes( blockType, - normalizedBlock.innerDom, - normalizedBlock.attrs + normalizedBlock.innerHTML, + normalizedBlock.attrs, + normalizedBlock.innerDom ), parsedInnerBlocks );