@@ -85,7 +85,57 @@ function preface(title,options) {
85
85
} ,
86
86
] ,
87
87
} ,
88
- ]
88
+ ] ,
89
+ localBiblio : {
90
+ "OpenAPI-Learn" : {
91
+ title : "OpenAPI - Getting started, and the specification explained" ,
92
+ href : "https://learn.openapis.org/" ,
93
+ publisher : "OpenAPI Initiative"
94
+ } ,
95
+ "OpenAPI-Registry" : {
96
+ title : "OpenAPI Initiative Registry" ,
97
+ href : "https://spec.openapis.org/registry/index.html" ,
98
+ publisher : "OpenAPI Initiative"
99
+ } ,
100
+ //TODO: remove localBiblio once Specref PRs https://github.com/tobie/specref/pulls/ralfhandl are merged
101
+ "JSON-Schema-Validation-04" : {
102
+ authors : [ "Kris Zyp" , "Francis Galiegue" , "Gary Court" ] ,
103
+ href : "https://datatracker.ietf.org/doc/html/draft-fge-json-schema-validation-00" ,
104
+ publisher : "Internet Engineering Task Force (IETF)" ,
105
+ status : "Internet-Draft" ,
106
+ title : "JSON Schema: interactive and non interactive validation. Draft 4" ,
107
+ date : "1 February 2013"
108
+ } ,
109
+ "JSON-Schema-05" : {
110
+ authors : [ "Austin Wright" ] ,
111
+ href : "https://datatracker.ietf.org/doc/html/draft-wright-json-schema-00" ,
112
+ publisher : "Internet Engineering Task Force (IETF)" ,
113
+ status : "Internet-Draft" ,
114
+ title : "JSON Schema: A Media Type for Describing JSON Documents. Draft 5" ,
115
+ date : "13 October 2016"
116
+ } ,
117
+ "JSON-Schema-Validation-05" : {
118
+ authors : [ "Austin Wright" , "G. Luff" ] ,
119
+ href : "https://datatracker.ietf.org/doc/html/draft-wright-json-schema-validation-00" ,
120
+ publisher : "Internet Engineering Task Force (IETF)" ,
121
+ status : "Internet-Draft" ,
122
+ title : "JSON Schema Validation: A Vocabulary for Structural Validation of JSON. Draft 5" ,
123
+ date : "13 October 2016"
124
+ } ,
125
+ "JSON-Schema-Validation-2020-12" : {
126
+ authors : [ "Austin Wright" , "Henry Andrews" , "Ben Hutton" ] ,
127
+ href : "https://datatracker.ietf.org/doc/html/draft-bhutton-json-schema-validation-00" ,
128
+ publisher : "Internet Engineering Task Force (IETF)" ,
129
+ status : "Internet-Draft" ,
130
+ title : "JSON Schema Validation: A Vocabulary for Structural Validation of JSON. Draft 2020-12" ,
131
+ date : "8 December 2020"
132
+ } ,
133
+ "SPDX" : {
134
+ href : "https://spdx.org/licenses/" ,
135
+ title : "SPDX License List" ,
136
+ publisher : "Linux Foundation"
137
+ }
138
+ }
89
139
} ;
90
140
91
141
let preface = `<!DOCTYPE html><html lang="en"><head><meta charset="UTF-8"><title>${ md . utils . escapeHtml ( title ) } </title>` ;
@@ -115,6 +165,7 @@ function preface(title,options) {
115
165
preface += 'table tr:nth-child(2n) { background-color: #f6f8fa; }' ;
116
166
preface += 'pre { background-color: #f6f8fa !important; }' ;
117
167
preface += 'code { color: #c83500 } th code { color: inherit }' ;
168
+ preface += 'a.bibref { text-decoration: underline;}' ;
118
169
preface += fs . readFileSync ( path . resolve ( __dirname , 'gist.css' ) , 'utf8' ) . split ( '\n' ) . join ( ' ' ) ;
119
170
preface += '</style>' ;
120
171
preface += `<h1 id="title">${ title . split ( '|' ) [ 0 ] } </h1>` ;
@@ -269,46 +320,52 @@ for (let l in lines) {
269
320
line = line . replace ( 'RFC [' , '[RFC' ) ;
270
321
line = line . replace ( '[Authorization header as defined in ' , 'Authorization header as defined in [' ) ;
271
322
line = line . replace ( '[JSON Pointer]' , 'JSON Pointer [RFC6901]' ) ; // only in 2.0.md
323
+ line = line . replace ( '[media type range](https://tools.ietf.org/html/rfc7231#appendix-D) ' , 'media type range, see [RFC7231](https://tools.ietf.org/html/rfc7231#appendix-D), ' ) ;
272
324
273
- //TODO: more "hidden" RFC references in older specs, for example
274
- // [media type range](https://tools.ietf.org/html/rfc7231#appendix-D)
275
- // [ABNF](https://tools.ietf.org/html/rfc5234)
276
-
277
- //TODO: unconventional references to RFCs in 3.0.4 and 3.1.1, for example
278
- // [RFC3986 §5.1.2 – 5.1.4](https://tools.ietf.org/html/rfc3986#section-5.1.2)
279
- // RFC6570 [mentions](https://www.rfc-editor.org/rfc/rfc6570.html#section-2.4.2)
280
- // [are not](https://datatracker.ietf.org/doc/html/rfc3986#appendix-A)
281
- // [special behavior](https://www.rfc-editor.org/rfc/rfc1866#section-8.2.1)
282
- // [RFC6570 considers to be _undefined_](https://datatracker.ietf.org/doc/html/rfc6570#section-2.3)
283
-
284
- if ( line . indexOf ( '[RFC' ) >= 0 ) {
285
- // also detect [RFC4648 §3.2] etc. in 3.0.4.md and 3.1.1.md
286
- line = line . replace ( / \[ R F C ? ( [ 0 - 9 ] { 1 , 5 } ) ( § [ 0 - 9 . - ] + ) ? \] / g, function ( match , group1 ) {
287
- // console.warn('Fixing RFC reference',match,group1);
288
- return '[[RFC' + group1 + ']]' ;
289
- } ) ;
290
- }
291
-
292
- //TODO: non-link mentions of RFCs in 3.0.4 and 3.1.1, for example
293
- // RFC3986's definition of [reserved](https://datatracker.ietf.org/doc/html/rfc3986#section-2.2)
325
+ line = line . replace ( / \[ R F C ? ( [ 0 - 9 ] { 1 , 5 } ) \] \( / g, '[[RFC$1]](' ) ;
294
326
295
327
// harmonize RFC URLs
296
- line = line . replace ( 'http://www.ietf.org/rfc/rfc2119.txt' , 'https://tools.ietf.org/html/rfc2119' ) ; // only in 2.0.md
328
+ //TODO: harmonize to https://www.rfc-editor.org/rfc/rfc*
329
+ line = line . replaceAll ( '](http://' , '](https://' ) ;
330
+ line = line . replace ( 'https://www.ietf.org/rfc/rfc2119.txt' , 'https://tools.ietf.org/html/rfc2119' ) ; // only in 2.0.md
297
331
line = line . replace ( / h t t p s : \/ \/ w w w .r f c - e d i t o r .o r g \/ r f c \/ r f c ( [ 0 - 9 ] { 1 , 5 } ) ( \. h t m l ) ? / g, 'https://tools.ietf.org/html/rfc$1' ) ;
298
- line = line . replaceAll ( 'https://datatracker.ietf.org/doc/html/rfc' , 'https://tools.ietf.org/html/rfc' ) ;
299
- line = line . replaceAll ( 'http://tools.ietf.org' , 'https://tools.ietf.org' ) ;
332
+ line = line . replaceAll ( 'https://datatracker.ietf.org/doc/html/' , 'https://tools.ietf.org/html/' ) ;
300
333
301
- // handle url fragments in RFC links and construct section titles links as well as RFC links
334
+ // handle url fragments in RFC links and construct section links as well as RFC links
302
335
line = line . replace ( / \] \] \( h t t p s : \/ \/ t o o l s .i e t f .o r g \/ h t m l \/ r f c ( [ 0 - 9 ] { 1 , 5 } ) \/ ? ( \# [ ^ ) ] * ) ? \) / g, function ( match , rfcNumber , fragment ) {
303
336
if ( fragment ) {
304
337
// Extract section title from the fragment
305
338
let sectionTitle = fragment . replace ( '#' , '' ) . replace ( / - / g, ' ' ) ;
306
339
sectionTitle = sectionTitle . charAt ( 0 ) . toUpperCase ( ) + sectionTitle . slice ( 1 ) ; // Capitalize the first letter
340
+ //TODO: section links to https://www.rfc-editor.org/rfc/rfc* for newer RFCs (>= 8700)
307
341
return `]] [${ sectionTitle } ](https://datatracker.ietf.org/doc/html/rfc${ rfcNumber } ${ fragment } )` ;
308
342
} else {
309
343
return ']]' ;
310
344
}
311
345
} ) ;
346
+
347
+ // non-RFC references
348
+ line = line . replace ( '[ABNF](https://tools.ietf.org/html/rfc5234)' , '[[ABNF]]' ) ;
349
+ line = line . replace ( '[CommonMark 0.27](https://spec.commonmark.org/0.27/)' , '[[CommonMark-0.27]]' ) ;
350
+ line = line . replace ( '[CommonMark syntax](https://spec.commonmark.org/)' , '[[CommonMark]] syntax' ) ;
351
+ line = line . replace ( 'CommonMark markdown formatting' , '[[CommonMark]] markdown formatting' ) ;
352
+ line = line . replace ( 'consult http://www.w3.org/TR/html401/interact/forms.html#h-17.13.4)' , 'consult [[HTML401]] [Section 17.13.4](http://www.w3.org/TR/html401/interact/forms.html#h-17.13.4)' ) ;
353
+ line = line . replace ( '[IANA Status Code Registry](https://www.iana.org/assignments/http-status-codes/http-status-codes.xhtml)' , '[[IANA-HTTP-STATUS-CODES|IANA Status Code Registry]]' ) ;
354
+ line = line . replace ( '[IANA Authentication Scheme registry](https://www.iana.org/assignments/http-authschemes/http-authschemes.xhtml)' , '[[IANA-HTTP-AUTHSCHEMES]]' ) ;
355
+ line = line . replace ( '[JSON Schema Specification Draft 4](https://json-schema.org/)' , '[[JSON-Schema-04|JSON Schema Specification Draft 4]]' ) ;
356
+ line = line . replace ( '[JSON Schema Core](https://tools.ietf.org/html/draft-zyp-json-schema-04)' , '[[JSON-Schema-04|JSON Schema Core]]' ) ;
357
+ line = line . replace ( '[JSON Schema Validation](https://tools.ietf.org/html/draft-fge-json-schema-validation-00)' , '[[JSON-Schema-Validation-04|JSON Schema Validation]]' ) ;
358
+ line = line . replace ( '[JSON Schema Specification Wright Draft 00](https://json-schema.org/)' , '[[JSON-Schema-05|JSON Schema Specification Wright Draft 00]]' ) ;
359
+ line = line . replace ( '[JSON Schema Core](https://tools.ietf.org/html/draft-wright-json-schema-00)' , '[[JSON-Schema-05|JSON Schema Core]]' ) ;
360
+ line = line . replace ( '[JSON Schema Validation](https://tools.ietf.org/html/draft-wright-json-schema-validation-00)' , '[[JSON-Schema-Validation-05|JSON Schema Validation]]' ) ;
361
+ line = line . replace ( '[JSON Schema Specification Draft 2020-12](https://tools.ietf.org/html/draft-bhutton-json-schema-00)' , '[[JSON-Schema-2020-12|JSON Schema Specification Draft 2020-12]]' ) ;
362
+ line = line . replace ( '[JSON Schema Core](https://tools.ietf.org/html/draft-bhutton-json-schema-00)' , '[[JSON-Schema-2020-12|JSON Schema Core]]' ) ;
363
+ line = line . replace ( '[JSON Schema Validation](https://tools.ietf.org/html/draft-bhutton-json-schema-validation-00)' , '[[JSON-Schema-Validation-2020-12|JSON Schema Validation]]' ) ;
364
+ line = line . replace ( '[SPDX](https://spdx.org/licenses/)' , '[[SPDX]]' ) ;
365
+ line = line . replace ( '[XML namespaces](https://www.w3.org/TR/xml-names11/)' , '[[xml-names11|XML namespaces]]' ) ;
366
+ line = line . replace ( 'JSON standards. YAML,' , '[[RFC7159|JSON]] standards. [[YAML|YAML]],' ) ; // 2.0.md only
367
+ line = line . replace ( 'JSON or YAML format.' , '[[RFC7159|JSON]] or [[YAML|YAML]] format.' ) ;
368
+ line = line . replace ( / Y A M L v e r s i o n \[ 1 \. 2 \] \( h t t p s : \/ \/ ( w w w \. ) ? y a m l \. o r g \/ s p e c \/ 1 \. 2 \/ s p e c \. h t m l \) / , '[[YAML|YAML version 1.2]]' ) ;
312
369
}
313
370
314
371
if ( ! inCodeBlock && line . indexOf ( '](../' ) >= 0 ) {
@@ -325,8 +382,6 @@ for (let l in lines) {
325
382
let delta = heading - prevHeading ;
326
383
if ( delta > 1 ) console . warn ( delta , line ) ;
327
384
if ( delta > 0 ) delta = 1 ;
328
- //if (delta<0) delta = -1;
329
- // if (Math.abs(delta)>1) console.warn(delta,line);
330
385
let prefix = '' ;
331
386
let newSection = '<section>' ;
332
387
if ( line . includes ( '## Version ' ) ) {
@@ -358,8 +413,6 @@ for (let l in lines) {
358
413
359
414
s = preface ( `OpenAPI Specification v${ argv . subtitle } | Introduction, Definitions, & More` , argv ) + '\n\n' + lines . join ( '\n' ) ;
360
415
let out = md . render ( s ) ;
361
- out = out . replace ( / \[ ( [ R G B ] ) \] / g, function ( match , group1 ) {
362
- console . warn ( 'Fixing' , match , group1 ) ;
363
- return '[' + group1 + ']' ;
364
- } ) ;
416
+ out = out . replace ( / \[ ( [ R G B ] ) \] / g, '[$1]' ) ;
417
+ out = out . replace ( '[[IANA-HTTP-AUTHSCHEMES]]' , '[[IANA-HTTP-AUTHSCHEMES|IANA Authentication Scheme registry]]' ) ;
365
418
console . log ( out ) ;
0 commit comments