rehype-pretty / rehype-pretty-code

Beautiful code blocks for Markdown or MDX.
https://rehype-pretty.pages.dev
MIT License
998 stars 63 forks source link

[Question] Pass metadata from code-block as data-attributes #206

Closed dimitrisnl closed 2 months ago

dimitrisnl commented 3 months ago

Hello!

Thank you for this library, it has saved my bacon.

I have a question, is it possible to take these metastrings, and have them as data-attributes in the pre block?

```ts title="title" meta-foo="something" meta-bar="other"
data-rehype-pretty-code-meta-foo="something"
data-rehype-pretty-code-meta-bar="another"

Thanks!

o-az commented 2 months ago

Are you asking if it's possible to do it currently on your end or for the library to make it behave like this? The answer to the former is no afaict.

To the latter question:

It's definitely possible. Take a look at how the copy button plugin works and it should give you an idea:

https://github.com/rehype-pretty/rehype-pretty-code/blob/master/packages/transformers/src/copy-button.ts

If you think this would be useful then we can add it to the library.

dimitrisnl commented 2 months ago

Thanks, I'll close it.