Skip to content

Commit 9b0d2d3

Browse files
committed
Add grouping selectors
1 parent 20d1c09 commit 9b0d2d3

File tree

3 files changed

+22
-2
lines changed

3 files changed

+22
-2
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,9 @@ select(ast, 'paragraph emphasis > text')
2727
- [x] Child selectors: `paragraph > text`
2828
- [x] Sibling selectors: `paragraph ~ text`
2929
- [x] Adjacent sibling selectors: `paragraph + text`
30+
- [x] Group selectors: `paragraph, text`
3031
- [ ] Attribute selectors: `text[value*="substr"]`
3132
- [ ] Universal selectors: `*`
32-
- [ ] Group selectors: `paragraph, text`
3333

3434
## API
3535

lib/select.js

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,17 @@
11
'use strict';
22

3-
43
var select = exports;
54

65

6+
select.selectors = function (selector, ast) {
7+
var result = [];
8+
selector.selectors.forEach(function (selector) {
9+
append(result, select.ruleSet(selector, ast));
10+
});
11+
return result;
12+
};
13+
14+
715
select.ruleSet = function (selector, ast) {
816
return select.rule(selector.rule, ast);
917
};

test/test.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,3 +71,15 @@ test('siblings', function (t) {
7171
]);
7272
t.end();
7373
});
74+
75+
76+
test('grouping', function (t) {
77+
t.deepEqual(select(ast, 'list, heading + heading'), [
78+
path(ast, [4]),
79+
path(ast, [4, 1, 1]),
80+
path(ast, [4, 1, 1, 0, 1]),
81+
path(ast, [6]),
82+
path(ast, [1])
83+
]);
84+
t.end();
85+
});

0 commit comments

Comments
 (0)