30
30
var CONSTANTS = {
31
31
DIAGRAM_WIDTH : 800 ,
32
32
DIAGRAM_HEIGHT : 500
33
- } ;
33
+ } ,
34
+ TOC_HEAD = "# Table of Contents" ;
34
35
35
36
GLOBAL . window = GLOBAL . window || GLOBAL ; // nomnoml expects window to be defined
36
37
( function ( ) {
@@ -44,6 +45,7 @@ GLOBAL.window = GLOBAL.window || GLOBAL; // nomnoml expects window to be define
44
45
split = require ( "split" ) ,
45
46
stream = require ( "stream" ) ,
46
47
nomnoml = require ( 'nomnoml' ) ,
48
+ toc = require ( "markdown-toc" ) ,
47
49
Canvas = require ( 'canvas' ) ,
48
50
options = require ( "minimist" ) ( process . argv . slice ( 2 ) ) ;
49
51
@@ -110,6 +112,9 @@ GLOBAL.window = GLOBAL.window || GLOBAL; // nomnoml expects window to be define
110
112
done ( ) ;
111
113
} ;
112
114
transform . _flush = function ( done ) {
115
+ // Prepend table of contents
116
+ markdown =
117
+ [ TOC_HEAD , toc ( markdown ) . content , "" , markdown ] . join ( "\n" ) ;
113
118
this . push ( "<html><body>\n" ) ;
114
119
this . push ( marked ( markdown ) ) ;
115
120
this . push ( "\n</body></html>\n" ) ;
@@ -133,8 +138,8 @@ GLOBAL.window = GLOBAL.window || GLOBAL; // nomnoml expects window to be define
133
138
customRenderer . link = function ( href , title , text ) {
134
139
// ...but only if they look like relative paths
135
140
return ( href || "" ) . indexOf ( ":" ) === - 1 && href [ 0 ] !== "/" ?
136
- renderer . link ( href . replace ( / \. m d / , ".html" ) , title , text ) :
137
- renderer . link . apply ( renderer , arguments ) ;
141
+ renderer . link ( href . replace ( / \. m d / , ".html" ) , title , text ) :
142
+ renderer . link . apply ( renderer , arguments ) ;
138
143
} ;
139
144
return customRenderer ;
140
145
}
0 commit comments