Using custom html elements with RehypeStringify #136
-
I have a processor that is adding a custom html element const testProcessor = unified()
.use(remarkParse)
.use(remarkGfm)
.use(customPlugin)
.use(remarkRehype, {passThrough: ['custom-element'] })
.use(rehypeRaw, {passThrough: ['custom-element']})
.use(rehypeStringify); the plugin has a visitor that adds it like so: const visitor: Visitor<Blockquote> = function (node, i, parent) {
...
const customElement: Literal = {
type: 'custom-element',
data: {
'attr': "attribute value",
},
value: "text"
};
parent!.children[i!] = customElement;
}; when running this, I get the following error when running
Is there a way to specify to rehypeStringify that |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
Heya @vritant24! 👋 The error is happening because If so a few ideas:
|
Beta Was this translation helpful? Give feedback.
Heya @vritant24! 👋
The error is happening because
custom-element
is not a node type inhast
https://github.com/syntax-tree/hastBased off your previous question https://github.com/orgs/rehypejs/discussions/135
I'm assuming your intent is to serialize an HTML custom element.
If so a few ideas:
Element
type from@types/hast
to ensure it is the right structure. (see: https://www.npmjs.com/package/@types/hast)hast
Element
will have atype: 'Element'
andtagName: 'custom-element'
. (see https://github.com/syntax-tree/hast#element)hast
node in the middle ofmdast
consider either:rehype
plugin, and ru…