Skip to content

Commit 8070369

Browse files
committed
First bunch of non-RFC normative references
1 parent 465fcb3 commit 8070369

File tree

1 file changed

+39
-19
lines changed

1 file changed

+39
-19
lines changed

scripts/md2html/md2html.js

Lines changed: 39 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,20 @@ function preface(title,options) {
8585
},
8686
],
8787
},
88-
]
88+
],
89+
//TODO: remove localBiblio once Specref PR https://github.com/tobie/specref/pulls/ralfhandl is merged
90+
localBiblio: {
91+
CommonMark: {
92+
title: "CommonMark Spec",
93+
href: "https://spec.commonmark.org/",
94+
},
95+
"CommonMark-0.27": {
96+
title: "CommonMark Spec Version 0.27",
97+
href: "https://spec.commonmark.org/0.27/",
98+
date: "2016-11-18",
99+
authors: ["John MacFarlane"]
100+
}
101+
}
89102
};
90103

91104
let preface = `<!DOCTYPE html><html lang="en"><head><meta charset="UTF-8"><title>${md.utils.escapeHtml(title)}</title>`;
@@ -269,46 +282,55 @@ for (let l in lines) {
269282
line = line.replace('RFC [','[RFC');
270283
line = line.replace('[Authorization header as defined in ','Authorization header as defined in [');
271284
line = line.replace('[JSON Pointer]','JSON Pointer [RFC6901]'); // only in 2.0.md
272-
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)
285+
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), ');
283286

284287
if (line.indexOf('[RFC')>=0) {
285288
// also detect [RFC4648 §3.2] etc. in 3.0.4.md and 3.1.1.md
289+
//TODO: TDC decision: fix in source markdown
286290
line = line.replace(/\[RFC ?([0-9]{1,5})( §[0-9 .-]+)?\]/g,function(match,group1){
287-
// console.warn('Fixing RFC reference',match,group1);
291+
//TODO: use string pattern with $1 instead of function
288292
return '[[RFC'+group1+']]';
289293
});
290294
}
291295

292-
//TODO: non-link mentions of RFCs in 3.0.4 and 3.1.1, for example
296+
//TODO: TDC decision: fix unconventional references to RFCs in 3.0.4 and 3.1.1, for example
297+
// [RFC3986 §5.1.2 – 5.1.4](https://tools.ietf.org/html/rfc3986#section-5.1.2)
298+
// RFC6570 [mentions](https://www.rfc-editor.org/rfc/rfc6570.html#section-2.4.2)
299+
// [are not](https://datatracker.ietf.org/doc/html/rfc3986#appendix-A)
300+
// [special behavior](https://www.rfc-editor.org/rfc/rfc1866#section-8.2.1)
301+
// [RFC6570 considers to be _undefined_](https://datatracker.ietf.org/doc/html/rfc6570#section-2.3)
302+
303+
//TODO: TDC decision: fix non-link mentions of RFCs etc. in 3.0.4 and 3.1.1, for example
293304
// RFC3986's definition of [reserved](https://datatracker.ietf.org/doc/html/rfc3986#section-2.2)
294305

295306
// 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
307+
//TODO: harmonize to https://www.rfc-editor.org/rfc/rfc*
308+
line = line.replaceAll('](http://','](https://');
309+
line = line.replace('https://www.ietf.org/rfc/rfc2119.txt','https://tools.ietf.org/html/rfc2119'); // only in 2.0.md
297310
line = line.replace(/https:\/\/www.rfc-editor.org\/rfc\/rfc([0-9]{1,5})(\.html)?/g,'https://tools.ietf.org/html/rfc$1');
298311
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');
300312

301-
// handle url fragments in RFC links and construct section titles links as well as RFC links
313+
// handle url fragments in RFC links and construct section links as well as RFC links
302314
line = line.replace(/\]\]\(https:\/\/tools.ietf.org\/html\/rfc([0-9]{1,5})\/?(\#[^)]*)?\)/g, function(match, rfcNumber, fragment) {
303315
if (fragment) {
304316
// Extract section title from the fragment
305317
let sectionTitle = fragment.replace('#', '').replace(/-/g, ' ');
306318
sectionTitle = sectionTitle.charAt(0).toUpperCase() + sectionTitle.slice(1); // Capitalize the first letter
319+
//TODO: section links to https://www.rfc-editor.org/rfc/rfc* for newer RFCs (>= 8700)
307320
return `]] [${sectionTitle}](https://datatracker.ietf.org/doc/html/rfc${rfcNumber}${fragment})`;
308321
} else {
309322
return ']]';
310323
}
311324
});
325+
326+
// non-RFC references
327+
line = line.replace('[ABNF](https://tools.ietf.org/html/rfc5234)','[[ABNF]]');
328+
line = line.replace('[CommonMark 0.27](https://spec.commonmark.org/0.27/)','[[CommonMark-0.27]]');
329+
line = line.replace('[CommonMark syntax](https://spec.commonmark.org/)','[[CommonMark]] syntax');
330+
line = line.replace('CommonMark markdown formatting','[[CommonMark]] markdown formatting');
331+
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)');
332+
//TODO
333+
line = line.replace(/YAML version \[1\.2\]\(https:\/\/(www\.)?yaml\.org\/spec\/1\.2\/spec\.html\)/,'[[YAML]] version 1.2');
312334
}
313335

314336
if (!inCodeBlock && line.indexOf('](../') >= 0) {
@@ -325,8 +347,6 @@ for (let l in lines) {
325347
let delta = heading-prevHeading;
326348
if (delta>1) console.warn(delta,line);
327349
if (delta>0) delta = 1;
328-
//if (delta<0) delta = -1;
329-
// if (Math.abs(delta)>1) console.warn(delta,line);
330350
let prefix = '';
331351
let newSection = '<section>';
332352
if (line.includes('## Version ')) {

0 commit comments

Comments
 (0)