diff --git a/src/editor/processors/blocks-stream-processor/index.js b/src/editor/processors/blocks-stream-processor/index.js index f30e563..f63cbba 100644 --- a/src/editor/processors/blocks-stream-processor/index.js +++ b/src/editor/processors/blocks-stream-processor/index.js @@ -109,29 +109,7 @@ export default class BlocksStreamProcessor { const parsed = JSON.parse(completedJson); if (Array.isArray(parsed) && parsed.length > 0) { - const contentMatches = [ - ...jsonContent.matchAll( - /"content"\s*:\s*"([^"]*)(?:[^"]*)?/g - ), - ]; - - const updatedBlocks = parsed.map((block, index) => { - if ( - block.name === 'core/paragraph' && - contentMatches[index] - ) { - return { - ...block, - attributes: { - ...block.attributes, - content: contentMatches[index][1], - }, - }; - } - return block; - }); - - const transformedBlocks = updatedBlocks + const transformedBlocks = parsed .map((block) => this.transformToBlock(block)) .filter(Boolean); @@ -326,9 +304,14 @@ export default class BlocksStreamProcessor { .filter(Boolean) : []; + const attributes = blockData.attributes || {}; + + // Recursively process attributes + const processedAttributes = this.processAttributes(attributes); + return createBlock( blockData.name, - blockData.attributes || {}, + processedAttributes, innerBlocks ); } catch (error) { @@ -337,6 +320,20 @@ export default class BlocksStreamProcessor { } } + processAttributes(attributes) { + const processedAttributes = {}; + + for (const [key, value] of Object.entries(attributes)) { + if (typeof value === 'object' && value !== null) { + processedAttributes[key] = this.processAttributes(value); + } else { + processedAttributes[key] = value; + } + } + + return processedAttributes; + } + async dispatchBlocks(blocks, isFinal = false) { const now = Date.now(); const timeSinceLastUpdate = now - this.lastUpdate;