milesj / interweave

🌀 React library to safely render HTML, filter attributes, autowrap text with matchers, render emoji characters, and much more.
https://interweave.dev
MIT License
1.09k stars 38 forks source link

Transform Docs Update Suggestions #237

Open jamesmart77 opened 2 years ago

jamesmart77 commented 2 years ago

Hey there! Awesome library!

After to digging around a little because my transform function wasn't working like I expected based from the docs example, I thought offering a suggestion would be helpful.

Since the reference a tagName === 'a', I expected just that, a lowercase 'a'. But turns out tagNames are actually uppercase. So maybe one of the following changes?

function transform(node: HTMLElement, children: Node[]): React.ReactNode {
    if (node.tagName === 'A') {
        return <Link href={node.getAttribute('href')}>{children}</Link>;
    }
}

OR

function transform(node: HTMLElement, children: Node[]): React.ReactNode {
    if (node.tagName.toLowerCase() === 'a') {
        return <Link href={node.getAttribute('href')}>{children}</Link>;
    }
}