File tree 3 files changed +30
-3
lines changed
3 files changed +30
-3
lines changed Original file line number Diff line number Diff line change @@ -6,9 +6,9 @@ var dot = '.'.charCodeAt(0)
6
6
var hash = '#' . charCodeAt ( 0 )
7
7
8
8
/* Parse a simple CSS selector into a HAST node. */
9
- function parse ( selector ) {
9
+ function parse ( selector , defaultTagName ) {
10
10
var value = selector || ''
11
- var name = 'div'
11
+ var name = defaultTagName || 'div'
12
12
var props = { }
13
13
var index = - 1
14
14
var length = value . length
Original file line number Diff line number Diff line change @@ -29,7 +29,7 @@ Yields:
29
29
30
30
## API
31
31
32
- ### ` parseSelector([selector]) `
32
+ ### ` parseSelector([selector][, defaultTagName] ) `
33
33
34
34
Parse a CSS ` selector ` to a [ HAST] [ ] node.
35
35
@@ -39,6 +39,11 @@ Parse a CSS `selector` to a [HAST][] node.
39
39
and an ID (` #baz ` ). Multiple classes are allowed. Uses the last ID if
40
40
multiple IDs are found.
41
41
42
+ ###### ` defaultTagName `
43
+
44
+ ` string ` , optional, defaults to ` div ` — Tag name to use if ` selector ` does not
45
+ specify one.
46
+
42
47
###### Returns
43
48
44
49
[ ` Node ` ] [ hast ] .
Original file line number Diff line number Diff line change @@ -26,6 +26,28 @@ test('parseSelector()', function(t) {
26
26
'should return an element with a tag-name when given a tag-name'
27
27
)
28
28
29
+ t . deepEqual (
30
+ parseSelector ( null , 'g' ) ,
31
+ {
32
+ type : 'element' ,
33
+ tagName : 'g' ,
34
+ properties : { } ,
35
+ children : [ ]
36
+ } ,
37
+ 'should return an `defaultTagName` if no tag name is defined in `selector` (#1)'
38
+ )
39
+
40
+ t . deepEqual (
41
+ parseSelector ( '#id' , 'g' ) ,
42
+ {
43
+ type : 'element' ,
44
+ tagName : 'g' ,
45
+ properties : { id : 'id' } ,
46
+ children : [ ]
47
+ } ,
48
+ 'should return an `defaultTagName` if no tag name is defined in `selector` (#2)'
49
+ )
50
+
29
51
t . deepEqual (
30
52
parseSelector ( '.bar' ) ,
31
53
{
You can’t perform that action at this time.
0 commit comments