-
Notifications
You must be signed in to change notification settings - Fork 4.6k
Closed
Labels
Needs Technical FeedbackNeeds testing from a developer perspective.Needs testing from a developer perspective.[Type] BugAn existing feature does not function as intendedAn existing feature does not function as intended
Description
Dear Gutenberg Team,
the "Convert to Blocks" feature (content parser) seems to ignore element attributes on raw DOM Nodes.
By converting "RAW" blocks by custom transform rules, no attributes are available within the isMatch(node) callback even if they are defined in the legacy html sources.
Example Code to reproduce the issue
Plugin
wp.blocks.registerBlockType('test/myblock', {
// block element transformation/converting
transforms: {
from: [
{
type: 'raw',
priority: 4,
isMatch: function isMatch(node) {
// ALL kind of attributes/classes are MISSING
console.log("classes: ", node.classList.length);
console.log("attributes: ", node.attributes.length);
return false;
},
transform: function transform(node) {
// some custom transform rule
return wp.blocks.createBlock('core/codeblock', { content: node.textContent });
}
}
]
}
})Editor Content
<pre class="EnlighterJSRAW" data-enlighter-language="php">
define('ENLIGHTER_GUTENBERG_PLUGIN_PATH', dirname(__FILE__));
define('ENLIGHTER_GUTENBERG_PLUGIN_URL', plugins_url('/enlighter-gutenberg/'));
</pre>
<div class="echo">lalala</div>Current Behaviour
Attributes are ignored by the parser and not copied to the node passed to the transform callbacks isMatch(node) / transform(node`)
Expected Behaviour
ALL attributes should be copied to the node (and become available in isMatch(node) + transform(node) to apply custom transform rules.
This is absolutely required to convert legacy addons to blocks (lot of them are based on custom classes)
best regards, Andi
Metadata
Metadata
Assignees
Labels
Needs Technical FeedbackNeeds testing from a developer perspective.Needs testing from a developer perspective.[Type] BugAn existing feature does not function as intendedAn existing feature does not function as intended
