Hi,
I found the position, where it goes bonkers:
In the code I have posted, find the function 'local:content#4' and there find the 'switch' statement. Replace the beginning of it, up to the second 'case' expression, with this:
,switch ($t) case "html" return ( attribute type { "html" } ,local:atomPlainTextConstruct($content,true()) )
and the function executes up to the 'error()' halt (which is just some useless stuff I did during development, as this code is not yet complete).