@@ -76,7 +76,10 @@ function preface(title,options) {
76
76
if ( options . respec ) {
77
77
preface += '<script src="../js/respec-oai.js" class="remove"></script>' ;
78
78
preface += `<script class="remove">var respecConfig = ${ JSON . stringify ( respec ) } ;</script>` ;
79
- preface += fs . readFileSync ( './analytics/google.html' , 'utf8' ) ;
79
+ try {
80
+ preface += fs . readFileSync ( './analytics/google.html' , 'utf8' ) ;
81
+ }
82
+ catch ( ex ) { }
80
83
preface += '</head><body>' ;
81
84
preface += '<style>' ;
82
85
preface += '#respec-ui { visibility: hidden; }' ;
@@ -167,6 +170,7 @@ let indents = [0];
167
170
// process the markdown
168
171
for ( let l in lines ) {
169
172
let line = lines [ l ] ;
173
+ let linkTarget ;
170
174
171
175
if ( line . startsWith ( '## Table of Contents' ) ) inTOC = true ;
172
176
if ( line . startsWith ( '<!-- /TOC' ) ) inTOC = false ;
@@ -213,7 +217,9 @@ for (let l in lines) {
213
217
let title = comp [ 1 ] ;
214
218
if ( inDefs ) title = '<dfn>' + title + '</dfn>' ;
215
219
let link = comp [ 0 ] . split ( '<a ' ) [ 1 ] . replace ( 'name=' , 'id=' ) ;
216
- line = ( '#' . repeat ( newIndent ) + ' <span ' + link + title + '</span>' ) ;
220
+ const anchor = link . split ( "'" ) . join ( '"' ) . split ( '"' ) [ 1 ] ;
221
+ line = '#' . repeat ( newIndent ) + ' <span>' + title + '</span>' ;
222
+ linkTarget = '<a id="' + anchor + '"></a>' ;
217
223
}
218
224
else {
219
225
let title = line . split ( '# ' ) [ 1 ] ;
@@ -303,7 +309,7 @@ for (let l in lines) {
303
309
line = prefix + md . render ( line ) ;
304
310
}
305
311
306
- lines [ l ] = line ;
312
+ lines [ l ] = ( linkTarget ? linkTarget : '' ) + line ;
307
313
}
308
314
309
315
s = preface ( `OpenAPI Specification v${ argv . subtitle } | Introduction, Definitions, & More` , argv ) + '\n\n' + lines . join ( '\n' ) ;
0 commit comments