-
Recently I learned about how to combine There is a pattern so far that I am following: import { name as isIdentifierName } from 'estree-util-is-identifier-name'
import { valueToEstree } from 'estree-util-value-to-estree'
export default function rehypeMdxPluginname({
name = 'variableSomething',
vfileDataKeyName = 'vfileDataKeyName'
} = {}) {
if (!isIdentifierName(name)) {
throw new Error(
`The name should be a valid identifier name, got: ${JSON.stringify(
name,
)}`,
)
}
return function transformer(tree, vfile) {
const value = vfile.data[vfileDataKeyName];
tree.children.unshift({
type: 'mdxjsEsm',
data: {
estree: {
type: 'Program',
sourceType: 'module',
body: [
{
type: 'ExportNamedDeclaration',
source: null,
specifiers: [],
declaration: {
type: 'VariableDeclaration',
kind: 'const',
declarations: [
{
type: 'VariableDeclarator',
id: { type: 'Identifier', name },
init: valueToEstree(value),
},
],
},
},
],
},
},
})
}
} Would it be helpful to document how to do this somewhere? Must plugins that do the Especially that this seems to be a copy-paste thing and change the configuration for the most part. Lastly, align in terms of how to publish things, I have been doing the following: import rehypeMyPlugin from 'rehype-my-plugin';
import rehypeMdxMyPlugin from 'rehype-my-plugin/mdx';
const remarkPlugins: = [
rehypeMyPlugin, // you must register this one first
rehypeMdxMyPlugin,
], What do you think? Trying to speak my mind and see if there is something that would make it easier for newbies and the ecosystem to figure out how to share and code the |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 4 replies
-
The problem is that there aren’t many MDX-specific plugins yet. For something to become a (documented) pattern I think there need to be different ways to do it, and “we” as a community” are converging on one particular way. One example that is unclear to me is how the data should flow: is For you last example: can you expand more practically on what you’re doing? |
Beta Was this translation helpful? Give feedback.
The problem is that there aren’t many MDX-specific plugins yet. For something to become a (documented) pattern I think there need to be different ways to do it, and “we” as a community” are converging on one particular way.
One example that is unclear to me is how the data should flow: is
file.meta
the source of truth? The document’s AST? Options? The ESM export? What direction should these things flow?For you last example: can you expand more practically on what you’re doing?