@@ -11,7 +11,7 @@ var LINK = 'link'
1111var LINK_REFERENCE = 'linkReference'
1212
1313// Transform a list of heading objects to a markdown list.
14- function contents ( map , tight ) {
14+ function contents ( map , tight , prefix ) {
1515 var minDepth = Infinity
1616 var index = - 1
1717 var length = map . length
@@ -38,14 +38,14 @@ function contents(map, tight) {
3838 index = - 1
3939
4040 while ( ++ index < length ) {
41- insert ( map [ index ] , table , tight )
41+ insert ( map [ index ] , table , tight , prefix )
4242 }
4343
4444 return table
4545}
4646
4747// Insert an entry into `parent`.
48- function insert ( entry , parent , tight ) {
48+ function insert ( entry , parent , tight , prefix ) {
4949 var children = parent . children
5050 var length = children . length
5151 var last = children [ length - 1 ]
@@ -62,30 +62,30 @@ function insert(entry, parent, tight) {
6262 {
6363 type : LINK ,
6464 title : null ,
65- url : '#' + entry . id ,
65+ url : '#' + ( prefix || '' ) + entry . id ,
6666 children : all ( entry . children )
6767 }
6868 ]
6969 } )
7070
7171 children . push ( item )
7272 } else if ( last && last . type === LIST_ITEM ) {
73- insert ( entry , last , tight )
73+ insert ( entry , last , tight , prefix )
7474 } else if ( last && last . type === LIST ) {
7575 entry . depth --
7676
77- insert ( entry , last , tight )
77+ insert ( entry , last , tight , prefix )
7878 } else if ( parent . type === LIST ) {
7979 item = listItem ( )
8080
81- insert ( entry , item , tight )
81+ insert ( entry , item , tight , prefix )
8282
8383 children . push ( item )
8484 } else {
8585 item = list ( )
8686 entry . depth --
8787
88- insert ( entry , item , tight )
88+ insert ( entry , item , tight , prefix )
8989
9090 children . push ( item )
9191 }
0 commit comments