Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

@shikijs/rehype: keep hast element data and properties #629

Open
4 tasks done
remcohaszing opened this issue Mar 18, 2024 · 1 comment
Open
4 tasks done

@shikijs/rehype: keep hast element data and properties #629

remcohaszing opened this issue Mar 18, 2024 · 1 comment

Comments

@remcohaszing
Copy link

Clear and concise description of the problem

With remark-rehype / MDX, the following markdown:

```js fileName="hello.js"
console.log('hello')
```

generates the following hast:

{
  type: 'element',
  tagName: 'pre',
  properties: {},
  children: [
    {
      type: 'element',
      tagName: 'code',
      properties: {
        className: 'language-js'
      },
      data: {
        meta: 'fileName="hello.js'
      },
      children: [
        {
          type: 'text',
          value: "console.log('hello')",
        }
      ]
    }
  ]
}

Given this has, Shiki replaces the pre element with a newly generated pre element. In this process the node’s data and properties are lost. It would be nice if Shiki keeps this information, so that other rehype plugins, such as rehype-mdx-code-props can use it. Likewise it could even be useful to preserve positional information, which is used for example by React devtools.

Suggested solution

It looks like some logic is needed in https://github.com/shikijs/shiki/blob/main/packages/core/src/code-to-hast.ts to be able to handle an existing pre and code element.

Alternative

No response

Additional context

No response

Validations

Contributes

  • If this feature request is accepted, I am willing to submit a PR to fix this issue
@antfu
Copy link
Member

antfu commented Apr 1, 2024

Sure, PR welcome!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants