-
Notifications
You must be signed in to change notification settings - Fork 20
Description
If "naively" creating custom tag mappings, you may run into this exception:
Uncaught RangeError: Maximum call stack size exceeded
at Object.code (myHtml5Preset.ts:160:12)
at myHtml5Preset.ts:72:72
at k8 (utils.js:7:33)
To reproduce, create a tag-rule that generates "itself as child". For example, for parsing within CKEditor 5, we need to represent [code]
as <pre><code>
. If we naively adapt the code from HTML5 Preset for Blockquote:
quote: (node) => toNode('blockquote', {}, [toNode('p', {}, node.content)]), |
We end up with a rule like this:
code: (node) => toNode('pre', {}, [toNode('code', {}, node.content)]),
The problem: As parents are processed first, the newly created code
will be processed afterward, so that we end up in an endless loop resulting in the RangeError
given above.
Workaround:
As the above "naive mapping" may be a result of not fully understanding the internal processing in BBob, the suggestion is to actually "fix" this issue by documenting this possible workaround as "best-practice":
code: (node) => toNode('pre', {}, [toNode('htmlCode', {}, node.content)]),
htmlCode: (node) => toNode('code', {}, node.content),
This workaround tricks the processing order by creating an intermediate node htmlCode
, that is resolved once the children of <pre>
created by the original code
rule are processed.