-
I'm trying to add some extra data in remark plugin. export function test(options:any = {}) {
return (tree: any) => {
visit(tree, 'paragraph', node => {
node.properties = {test: 1};
node.customData = "test";
visit(node, 'text', textNode => {
textNode.value = "new value";
textNode.properties = {test: 1};
textNode.customData = "test";
})
})
}
} Later when this data is passed down the line to "rehype" and then "react-markdown" the data is gone. const MDComponents = {
p: (props:any) => {
console.info("All my custom properties are gone",props);
return (
<p>
{props.children}
</p>
);
},
} |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 5 replies
-
You seem to be using TypeScript. TypeScript can be useful in this case, but you’re setting everything to The markdown syntax tree (called mdast, used by remark) does not have properties. You can’t set properties there. You‘re not supposed to. The HTML syntax tree (called hast, used by rehype) does have properties. You can set them there.
Indeed. You want to set properties in html/hast/rehype. |
Beta Was this translation helpful? Give feedback.
You seem to be using TypeScript. TypeScript can be useful in this case, but you’re setting everything to
any
s.The markdown syntax tree (called mdast, used by remark) does not have properties. You can’t set properties there. You‘re not supposed to.
The HTML syntax tree (called hast, used by rehype) does have properties. You can set them there.
Indeed. You want to set properties in html/hast/rehype.