rehype-pretty / rehype-pretty-code

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

`rehype-pretty-code` doesn't preserve the language if it's unknown #136

Closed jackyzha0 closed 11 months ago

jackyzha0 commented 11 months ago

Before upgrading to 0.12.1, Quartz used to have code that looks like this:

visit(tree, "code", (node: Code) => {
  if (node.lang === "mermaid") {
    node.data = {
      hProperties: {
        className: ["mermaid"],
      },
    }
  }
})

This would run in a remark plugin before rehype-pretty-code does. I'm guessing that the old implementation would respect the hProperties on the code block but shikiji straight up just replaces it? In any case, this would also be solved if data-language contained the code block language even if it isn't a recognized language (right now, it seems to default to the empty string if it's not detected)

jackyzha0 commented 11 months ago

Related issue within Quartz: https://github.com/jackyzha0/quartz/issues/638

jackyzha0 commented 11 months ago

https://github.com/atomiks/rehype-pretty-code/issues/69#issuecomment-1814395653 the crux of this issue seems to be the same one that this other comment mentions

is there a way to keep node.properties after it gets transformed into a div?

atomiks commented 11 months ago

@jackyzha0 I think the issue was the transformation of properties wasn't respecting the existing properties, can you check if the linked PR ^ fixes it?