Skip to content

Commit 4554d3a

Browse files
committed
Preserve section/page links
Thanks to @frankkilcommins
1 parent 5743d52 commit 4554d3a

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

scripts/md2html/md2html.js

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -283,8 +283,17 @@ for (let l in lines) {
283283
line = line.replace('https://xml2rfc.ietf.org/public/rfc/html/rfc','https://tools.ietf.org/html/rfc');
284284
line = line.replace('.html','');
285285
}
286-
line = line.replace(/\]\]\(https:\/\/tools.ietf.org\/html\/rfc[0-9]{1,5}\/?(\#.*?)?\)/g,function(match,group1){
287-
//return (group1 ? group1 : '')+']]';
286+
287+
//handle url fragments in RFC links and construct section titles links as well as RFC links
288+
line = line.replace(/\]\]\(https:\/\/tools.ietf.org\/html\/rfc([0-9]{1,5})(\/?\#.*?)?\)/g, function(match, rfcNumber, fragment) {
289+
if (fragment) {
290+
// Extract section title from the fragment
291+
let sectionTitle = fragment.replace('#', '').replace(/-/g, ' ');
292+
sectionTitle = sectionTitle.charAt(0).toUpperCase() + sectionTitle.slice(1); // Capitalize the first letter
293+
return `]] [${sectionTitle}](https://tools.ietf.org/html/rfc${rfcNumber}${fragment})`;
294+
} else {
295+
return ']]';
296+
}
288297
return ']]';
289298
});
290299
}

0 commit comments

Comments
 (0)