@@ -7,39 +7,40 @@ var xtend = require('xtend');
77var one = require ( './one' ) ;
88var handlers = require ( './handlers' ) ;
99
10- h . augment = augment ;
11-
1210function toMDAST ( tree , options ) {
13- options = options || { } ;
14- h . handlers = xtend ( handlers , options . handlers || { } ) ;
11+ var settings = options || { } ;
12+
13+ h . handlers = xtend ( handlers , settings . handlers || { } ) ;
14+ h . augment = augment ;
15+
1516 return one ( h , minify ( tree ) , null ) ;
16- }
1717
18- function h ( node , type , props , children ) {
19- var result ;
18+ function h ( node , type , props , children ) {
19+ var result ;
2020
21- if ( ! children && ( ( typeof props === 'object' && 'length' in props ) || typeof props === 'string' ) ) {
22- children = props ;
23- props = { } ;
24- }
21+ if ( ! children && ( ( typeof props === 'object' && 'length' in props ) || typeof props === 'string' ) ) {
22+ children = props ;
23+ props = { } ;
24+ }
25+
26+ result = xtend ( { type : type } , props ) ;
2527
26- result = xtend ( { type : type } , props ) ;
28+ if ( typeof children === 'string' ) {
29+ result . value = children ;
30+ } else if ( children ) {
31+ result . children = children ;
32+ }
2733
28- if ( typeof children === 'string' ) {
29- result . value = children ;
30- } else if ( children ) {
31- result . children = children ;
34+ return augment ( node , result ) ;
3235 }
3336
34- return augment ( node , result ) ;
35- }
37+ /* `right` is the finalized MDAST node,
38+ * created from `left`, a HAST node */
39+ function augment ( left , right ) {
40+ if ( left . position ) {
41+ right . position = left . position ;
42+ }
3643
37- /* `right` is the finalized MDAST node,
38- * created from `left`, a HAST node */
39- function augment ( left , right ) {
40- if ( left . position ) {
41- right . position = left . position ;
44+ return right ;
4245 }
43-
44- return right ;
4546}
0 commit comments