@@ -25,7 +25,6 @@ const common = require('./common.js');
25
25
const fs = require ( 'fs' ) ;
26
26
const marked = require ( 'marked' ) ;
27
27
const path = require ( 'path' ) ;
28
- const preprocess = require ( './preprocess.js' ) ;
29
28
const typeParser = require ( './type-parser.js' ) ;
30
29
31
30
module . exports = toHTML ;
@@ -42,76 +41,36 @@ marked.setOptions({
42
41
renderer : renderer
43
42
} ) ;
44
43
45
- // TODO(chrisdickinson): never stop vomiting / fix this.
46
- const gtocPath = path . resolve ( path . join (
47
- __dirname ,
48
- '..' ,
49
- '..' ,
50
- 'doc' ,
51
- 'api' ,
52
- '_toc.md'
53
- ) ) ;
54
- var gtocLoading = null ;
55
- var gtocData = null ;
44
+ const docPath = path . resolve ( __dirname , '..' , '..' , 'doc' ) ;
45
+
46
+ const gtocPath = path . join ( docPath , 'api' , '_toc.md' ) ;
47
+ const gtocMD = fs . readFileSync ( gtocPath , 'utf8' ) . replace ( / ^ @ \/ \/ .* $ / gm, '' ) ;
48
+ const gtocHTML = marked ( gtocMD ) . replace (
49
+ / < a h r e f = " ( .* ?) " / g,
50
+ ( all , href ) => `<a class="nav-${ toID ( href ) } " href="${ href } "`
51
+ ) ;
52
+
53
+ const templatePath = path . join ( docPath , 'template.html' ) ;
54
+ const template = fs . readFileSync ( templatePath , 'utf8' ) ;
55
+
56
56
var docCreated = null ;
57
57
var nodeVersion = null ;
58
58
59
59
/**
60
- * opts: input, filename, template, nodeVersion.
60
+ * opts: input, filename, nodeVersion.
61
61
*/
62
62
function toHTML ( opts , cb ) {
63
- const template = opts . template ;
64
-
65
63
nodeVersion = opts . nodeVersion || process . version ;
66
64
docCreated = opts . input . match ( DOC_CREATED_REG_EXP ) ;
67
65
68
- if ( gtocData ) {
69
- return onGtocLoaded ( ) ;
70
- }
71
-
72
- if ( gtocLoading === null ) {
73
- gtocLoading = [ onGtocLoaded ] ;
74
- return loadGtoc ( function ( err , data ) {
75
- if ( err ) throw err ;
76
- gtocData = data ;
77
- gtocLoading . forEach ( function ( xs ) {
78
- xs ( ) ;
79
- } ) ;
80
- } ) ;
81
- }
82
-
83
- if ( gtocLoading ) {
84
- return gtocLoading . push ( onGtocLoaded ) ;
85
- }
86
-
87
- function onGtocLoaded ( ) {
88
- const lexed = marked . lexer ( opts . input ) ;
89
- fs . readFile ( template , 'utf8' , function ( er , template ) {
90
- if ( er ) return cb ( er ) ;
91
- render ( {
92
- lexed : lexed ,
93
- filename : opts . filename ,
94
- template : template ,
95
- nodeVersion : nodeVersion ,
96
- analytics : opts . analytics ,
97
- } , cb ) ;
98
- } ) ;
99
- }
100
- }
101
-
102
- function loadGtoc ( cb ) {
103
- fs . readFile ( gtocPath , 'utf8' , function ( err , data ) {
104
- if ( err ) return cb ( err ) ;
105
-
106
- preprocess ( gtocPath , data , function ( err , data ) {
107
- if ( err ) return cb ( err ) ;
108
-
109
- data = marked ( data ) . replace ( / < a h r e f = " ( .* ?) " / gm, function ( a , m ) {
110
- return `<a class="nav-${ toID ( m ) } " href="${ m } "` ;
111
- } ) ;
112
- return cb ( null , data ) ;
113
- } ) ;
114
- } ) ;
66
+ const lexed = marked . lexer ( opts . input ) ;
67
+ render ( {
68
+ lexed : lexed ,
69
+ filename : opts . filename ,
70
+ template : template ,
71
+ nodeVersion : nodeVersion ,
72
+ analytics : opts . analytics ,
73
+ } , cb ) ;
115
74
}
116
75
117
76
function toID ( filename ) {
@@ -150,7 +109,7 @@ function render(opts, cb) {
150
109
template = template . replace ( / _ _ T O C _ _ / g, toc ) ;
151
110
template = template . replace (
152
111
/ _ _ G T O C _ _ / g,
153
- gtocData . replace ( `class="nav-${ id } ` , `class="nav-${ id } active` )
112
+ gtocHTML . replace ( `class="nav-${ id } ` , `class="nav-${ id } active` )
154
113
) ;
155
114
156
115
if ( opts . analytics ) {
0 commit comments