-
-
Notifications
You must be signed in to change notification settings - Fork 148
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
How to have hashtags render as links? #628
Comments
Codesandbox of the problem: https://codesandbox.io/p/sandbox/uiwjs-react-md-editor-issues-366-forked-3qx3l7?file=%2Findex.js |
rewrite: (node: any, index: any, parent: any) => {
if (node.type === "element") {
let text = getCodeString(node.children);
if (REG.test(text)) {
node.tagName = "a";
node.properties = {
href: "https://example.com",
};
}
}
}, |
For completeness sake, here's what I've settled with after some tweaking rehypeRewrite,
{
rewrite: (node: any, index: any, parent: any) => {
if (node.type === "element" && node.tagName != "a") {
let text = getCodeString(node.children);
let m;
let parts: any[] = [];
if (REG.test(text)) {
m = text.split(" ")
for (let element of m) {
if (REG.test(element)) {
parts.push(
{
type: "element",
tagName: "a",
properties: {
href: "https://google.ca",
},
children: [{ type: "text", value: " " + element + " " }],
})
} else {
parts.push(
{
type: 'element',
tagName: 'span',
properties: {},
children: [
{ type: 'text', value: element }
]
})
}
}
}
console.log(parts)
if (parts.length > 0) {
node.children = parts;
}
}
},
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hey all,
Trying to make a something like
#tag
render as a URL. Here's what I have so farThe regex properly matches the text but instead of the node being replaced with a link, it just doesn't render anything.
Any guidance on what I may be doing wrong would be much appreciated
The text was updated successfully, but these errors were encountered: