-
Lets say I have the following markdown # Some heading
<div data-something="abc">
Something
<div>
<div data-something="xyz">
</div>
and i have to select that If I console the {
"type": "mdxJsxFlowElement",
"name": "div",
"attributes": [
{
"type": "mdxJsxAttribute",
"name": "data-something",
"value": "abc"
}
], I can select all thes import { match } from 'unist-util-select';
const isMatch = matches("mdxJsxFlowElement", node); but this will select all the |
Beta Was this translation helpful? Give feedback.
Answered by
wooorm
Sep 5, 2023
Replies: 1 comment 4 replies
-
Don’t use select. It is likely slower than the better alternative. And the alternative makes your problem trivial to solve: https://github.com/syntax-tree/unist-util-select#when-should-i-use-this. import {visit} from 'unist-util-visit'
visit(tree, function (node) {
if (node.type === 'mdxJsxFlowElement' && /* put your extra conditions here */) {
}
}) |
Beta Was this translation helpful? Give feedback.
4 replies
Answer selected by
ChristianMurphy
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Don’t use select. It is likely slower than the better alternative. And the alternative makes your problem trivial to solve: https://github.com/syntax-tree/unist-util-select#when-should-i-use-this.