-
Hi, I have the following tree and using selectAll: import { selectAll } from 'hast-util-select';
import { h } from 'hastscript';
import { inspect } from 'unist-util-inspect';
const hast = h('body', [
h('div', [
h('div', [
h('p', 'first paragraph'),
]),
h('p', 'second paragraph'),
])
]);
console.log(inspect(selectAll('div > p', hast))); the resulting nodes are:
According to the documentation it should traverse the tree preorder. If I understand correctly, the the same example in the HTML DOM yields my expected result: <html>
<body>
<div>
<div>
<p>first paragraph</p>
</div>
<p>second paragraph</p>
</div>
<script>
document.querySelectorAll('div > p').forEach((p) => console.log(p.innerText));
</script>
</body>
</html> outputs:
workaroundof course I can use visit as a workaround: const list = [];
visit(hast, (node, idx, parent) => {
if (parent?.tagName === 'div' && node.tagName === 'p') {
list.push(node);
}
}); |
Beta Was this translation helpful? Give feedback.
Answered by
wooorm
Mar 18, 2022
Replies: 1 comment 1 reply
-
Interesting, presumably a bug yeah! |
Beta Was this translation helpful? Give feedback.
1 reply
Answer selected by
ChristianMurphy
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Interesting, presumably a bug yeah!