-
Notifications
You must be signed in to change notification settings - Fork 198
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
feat: preserve vfile data from unified processor #236
Conversation
|
for mdx, we could maybe convert any import { valueToEstree } from "estree-util-value-to-estree";
function convertVFileDataToExport() {
return function transformer(tree, vfile) {
const node = {
type: "mdxjsEsm",
data: {
estree: {
type: "Program",
sourceType: "module",
body: [
{
type: "ExportNamedDeclaration",
declaration: {
type: "VariableDeclaration",
declarations: [
{
type: "VariableDeclarator",
id: {
type: "Identifier",
name: "data",
},
init: valueToEstree(vfile.data),
},
],
kind: "const",
},
specifiers: [],
source: null,
},
],
},
},
};
tree.children.push(node);
};
} |
Thanks a lot for raising this PR @stefanprobst. I'm pretty busy right now but hope to find some time soon to act on this! 🤞 |
Hi @stefanprobst, I am really interested in this but primarily for mdx documents. I saw that the PR you raised seems to implement changes only for markdown. Wouldn't it make sense for mdx, too? |
hi, unfortunately there is no way to access
|
Thanks so much for taking the time to clarify and explain! Will use a custom hook as per your suggestion here for now. |
Thanks a lot again for opening this PR @stefanprobst. I've just given it a more thorough look and while I agree with the problems/use cases it addresses, I think there are some open questions/problems we should address before merging: 1. Increased document sizeAdding a A possible solution to this concern could be to introduce a configuration option to let users opt-in to this functionality. 2. Divergence of Markdown vs MDX behaviourTo what ever degree possible, I'd like to keep the behaviour of Markdown and MDX processing as similar as possible and avoid "gaps" / asymmetries in terms functionality, APIs and behaviour. Before merging this PR I'd like to better explore and implement ways to maintain the current level of consistency between the MD and MDX. As an alternative approach I could also imagine introducing a way to let the user expose remark/rehype/MDX processing data via |
thanks for your comments @schickling! some more thoughts: (i) increased document size
(ii) divergence of markdown and mdx behavior
(iii) use computed fields
|
This pull request has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. |
Still WIP. |
This pull request has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. |
unified
plugins can store custom information on the resultingVFile
on thedata
property. this can be used e.g. to pass a table of contents or similar.this PR preserves the information on
VFile.data
.note that this is done only for the
remark
pipeline,mdx-bundler
seems to not expose thevfile
unfortunately (although i haven't used it personally so i might be missing something)x-ref: #216