Skip to content

Instantly share code, notes, and snippets.

@ajitid
Last active September 1, 2021 04:39
Show Gist options
  • Save ajitid/ac920ab9a3f87e0581552ea335c1f043 to your computer and use it in GitHub Desktop.
Save ajitid/ac920ab9a3f87e0581552ea335c1f043 to your computer and use it in GitHub Desktop.
Parse Markdown links (not safe as its usage might create XSS attack vector)
export const Message: React.FC = ({ children }) => {
const msgTokens = parseMdLinks(children as string);
const content = msgTokens.map((t, idx) => {
if (t.type === "text") return t.text;
else if (t.type === "link")
return (
<a
key={idx}
href={t.link}
target="_blank"
rel="noopener noreferrer"
className="text-brand-blue-700 hover:text-brand-blue-500"
>
{t.name}
<ArrowUpRightIcon
size={14}
strokeWidth={3}
className="text-gray-500 inline-block"
/>
</a>
);
else return null;
});
return <div>{content}</div>;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment