Change markdown instruction to button #165
-
Hi, I'm trying to change a
and I want to transform it to something like: <button onclick="console.log("port is 8080")">name</button> So what I've done so far is have my markdown running through some compilers and I added my own custom pluggin: unified()
.use(remarkParse)
.use(remarkDirective)
.use(customPlugin) //my pluggin
.use(remarkStringify)
.process(markdown, (err, file) => {
if (err){
console.log(err)
} else {
const content = file.contents;
res.render('render', { markdown: content });
}
}) and my customPluggin is looking like: function customPlugin() {
return (tree, file) => {
visit(tree, (node, index, parent) => {
if (node.type === "textDirective" && node.name === "toButton") {
const {port, route, name, display} = node.attributes;
// create a button here and insert it in the markdown
}
})
}
} So I'm able to loop through the tree and select my textDirective with the info that I pass, but after quite some time on this, I'm still unsure on how to make that button and insert it in the markdown. Any help would be greatly appreciated! |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 5 replies
-
Could you share a runnable example of the issue? (using a codesandbox, there are some starters which could help https://codesandbox.io/s/remark-debug-ikwvx and https://codesandbox.io/s/remark-rehype-debug-4cz8v) |
Beta Was this translation helpful? Give feedback.
Could you share a runnable example of the issue? (using a codesandbox, there are some starters which could help https://codesandbox.io/s/remark-debug-ikwvx and https://codesandbox.io/s/remark-rehype-debug-4cz8v)
Do the examples in syntax-tree/unist#54 (comment) and or remarkjs/remark#867 (comment) help?