mirror of
https://github.com/danbulant/node-html-parser
synced 2026-06-19 06:31:30 +00:00
Merge pull request #12 from patrikpihlstrom/master
support ',' in query selectors
This commit is contained in:
commit
4b588b69e2
2 changed files with 9 additions and 0 deletions
|
|
@ -325,6 +325,14 @@ export class HTMLElement extends Node {
|
||||||
matcher = selector;
|
matcher = selector;
|
||||||
matcher.reset();
|
matcher.reset();
|
||||||
} else {
|
} else {
|
||||||
|
if (selector.includes(',')) {
|
||||||
|
const selectors = selector.split(',') as string[];
|
||||||
|
let result = [] as HTMLElement[];
|
||||||
|
selectors.forEach((s) => {
|
||||||
|
result = result.concat(this.querySelectorAll(s.trim()));
|
||||||
|
})
|
||||||
|
return result;
|
||||||
|
}
|
||||||
matcher = new Matcher(selector);
|
matcher = new Matcher(selector);
|
||||||
}
|
}
|
||||||
const res = [] as HTMLElement[];
|
const res = [] as HTMLElement[];
|
||||||
|
|
|
||||||
|
|
@ -310,6 +310,7 @@ describe('HTML Parser', function () {
|
||||||
root.querySelectorAll('span.a.b').should.eql([root.firstChild.firstChild.firstChild]);
|
root.querySelectorAll('span.a.b').should.eql([root.firstChild.firstChild.firstChild]);
|
||||||
root.querySelectorAll('#id .b').should.eql([root.firstChild.firstChild.firstChild]);
|
root.querySelectorAll('#id .b').should.eql([root.firstChild.firstChild.firstChild]);
|
||||||
root.querySelectorAll('#id span').should.eql(root.firstChild.firstChild.childNodes);
|
root.querySelectorAll('#id span').should.eql(root.firstChild.firstChild.childNodes);
|
||||||
|
root.querySelectorAll('#id, #id .b').should.eql([root.firstChild, root.firstChild.firstChild.firstChild]);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue