rehype-attr icon indicating copy to clipboard operation
rehype-attr copied to clipboard

Parsing as className instead of class for React

Open ramon-san opened this issue 1 year ago • 1 comments

First of all I'm sorry to open an issue in your GitHub repository! I really appreciate the tool you created and thank you for the work.

Main question

I was wondering if there is a way to parse markdown with this tool and give the attribute className instead of the regular class when using a comment like:

Some paragraph of my markdown file...
<!--rehype:className=regularText-->

The problem with this is that if I render things as .use(rehypeAttr, { properties: 'attr' }), this gives a translation that adds class to the resulting <p> instead of className. I'm asking this in the hope that something already exists, but if not I'd be happy to collaborate on some code for the implementation.

Another question

I was using ChatGPT to help me fix this, and it suggested a syntax similar to this:

.use(rehypeAttr, {
      p: { className: 'text-gray-700 my-10' },
      h1: { className: 'text-3xl font-bold' },
})

Is this valid? Because when I try to use it nothing happens.

ramon-san avatar Mar 29 '23 19:03 ramon-san

@ramon-san I think it would be better to design the API as follows:

.use(rehypeAttrs, {
  properties: 'attr',
  elements: {
    p: { className: 'text-gray-700 my-10' },
    h1: { className: 'text-3xl font-bold' },
  }
})

jaywcjlove avatar Apr 07 '23 09:04 jaywcjlove