File tree Expand file tree Collapse file tree 2 files changed +50
-4
lines changed Expand file tree Collapse file tree 2 files changed +50
-4
lines changed Original file line number Diff line number Diff line change @@ -12,27 +12,28 @@ function toMDAST(tree) {
12
12
}
13
13
14
14
function h ( node , type , props , children ) {
15
+ var result ;
15
16
if ( ! children && ( ( typeof props === 'object' && 'length' in props ) || typeof props === 'string' ) ) {
16
17
children = props ;
17
18
props = { } ;
18
19
}
19
20
20
- var result = augment ( node , { type : type } ) ;
21
+ result = xtend ( { type : type } , props ) ;
21
22
22
23
if ( typeof children === 'string' ) {
23
24
result . value = children ;
24
25
} else if ( children ) {
25
26
result . children = children ;
26
27
}
27
28
28
- return xtend ( result , props ) ;
29
+ return augment ( node , result ) ;
29
30
}
30
31
31
32
/* `right` is the finalized MDAST node,
32
33
* created from `left`, a HAST node */
33
34
function augment ( left , right ) {
34
- if ( left . value ) {
35
- right . value = left . value ;
35
+ if ( left . position ) {
36
+ right . position = left . position ;
36
37
}
37
38
38
39
return right ;
Original file line number Diff line number Diff line change @@ -42,6 +42,51 @@ test('core', function (t) {
42
42
'should ignore unknown voids'
43
43
) ;
44
44
45
+ var pos = {
46
+ left : {
47
+ line : 1 ,
48
+ column : 1 ,
49
+ offset : 0
50
+ } ,
51
+ right : {
52
+ line : 1 ,
53
+ column : 6 ,
54
+ offset : 5
55
+ }
56
+ } ;
57
+
58
+ t . deepEqual (
59
+ toMDAST ( {
60
+ type : 'root' ,
61
+ children : [ {
62
+ type : 'element' ,
63
+ tagName : 'p' ,
64
+ properties : { } ,
65
+ children : [ {
66
+ type : 'text' ,
67
+ value : 'Alpha' ,
68
+ position : pos
69
+ } ] ,
70
+ position : pos
71
+ } ] ,
72
+ position : pos
73
+ } ) ,
74
+ {
75
+ type : 'root' ,
76
+ children : [ {
77
+ type : 'paragraph' ,
78
+ children : [ {
79
+ type : 'text' ,
80
+ value : 'Alpha' ,
81
+ position : pos
82
+ } ] ,
83
+ position : pos
84
+ } ] ,
85
+ position : pos
86
+ } ,
87
+ 'should ignore unknown voids'
88
+ ) ;
89
+
45
90
t . end ( ) ;
46
91
} ) ;
47
92
You can’t perform that action at this time.
0 commit comments