-
-
Notifications
You must be signed in to change notification settings - Fork 374
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
Comments
Sure, PR welcome! |
I was also looking for the meta information from the code fence (the shiki/packages/rehype/src/core.ts Lines 117 to 128 in 4c1de34
But it only parses the meta string and passes the props if a custom shiki/packages/rehype/test/index.test.ts Lines 21 to 28 in 4c1de34
eg. I was able to get
export default withMDX({
options: {
remarkPlugins: [],
rehypePlugins: [
[
rehypeShiki,
{
theme: 'dark-plus',
addLanguageClass: true,
parseMetaString: (str) => {
return Object.fromEntries(
str.split(' ').reduce((prev, curr) => {
const [key, value] = curr.split('=');
const isNormalKey = /^[A-Z0-9]+$/i.test(key);
if (isNormalKey) prev = [...prev, [key, value || true]];
return prev;
}, []),
);
},
},
],
],
},
})(config); Would it be an acceptable smaller change to set I don't mean to invalidate the idea of keeping |
Clear and concise description of the problem
With
remark-rehype
/ MDX, the following markdown:generates the following hast:
Given this has, Shiki replaces the
pre
element with a newly generatedpre
element. In this process the node’sdata
andproperties
are lost. It would be nice if Shiki keeps this information, so that other rehype plugins, such asrehype-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
andcode
element.Alternative
No response
Additional context
No response
Validations
Contributes
The text was updated successfully, but these errors were encountered: