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.1k stars 38 forks source link

Add Tailwind classes in my html content #261

Closed harshalone closed 1 year ago

harshalone commented 1 year ago

Hi I am rendering my html

<Interweave 
                        content={post ? post.content : "" } 
                        matchers={['<p>', '<p className="text-3xl">']}
 /> 

But it is throwing error. What I want is simply add a class whenever there is a

tag.

How do I create this matcher and include into my nextjs app?

The documentation here does not explain it very well.

Should I create a file called myMatcher.js and include it into my component and then it will do the matching? how does it work? can you please explain with an example.

milesj commented 1 year ago

@harshalone Matches are class instances that replace content with regex, it's not an array of HTML tags.

Use a transformer instead: https://interweave.dev/docs/parser#replacing-elements