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

fix: allow spaces in variables #1035

Merged
merged 7 commits into from
Dec 5, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion __tests__/lib/mdast/variables/in.mdx
Original file line number Diff line number Diff line change
@@ -1 +1 @@
Hello, {user.name}
Hello, { user.name }
2 changes: 1 addition & 1 deletion __tests__/lib/mdast/variables/out.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
}
},
"type": "readme-variable",
"value": "{user.name}"
"value": "{ user.name }"
}
],
"position": {
Expand Down
2 changes: 1 addition & 1 deletion processor/transform/variables.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ const variables =
visit(tree, (node, index, parent) => {
if (!['mdxFlowExpression', 'mdxTextExpression'].includes(node.type) || !('value' in node)) return;

const match = node.value.match(/^user\.(?<value>.*)$/);
const match = node.value.match(/^\s*user\.(?<value>\S*)\s*$/);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think variable names can include spaces though? So this should still be .* right?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh no, that's so cursed

if (!match) return;

let variable = asMdx
Expand Down
Loading