Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add appendix "Informative references" to published spec documents #3786

Closed
wants to merge 4 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
46 changes: 41 additions & 5 deletions scripts/md2html/md2html.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,24 +47,60 @@ const md = require('markdown-it')({
}
});

function preface(title,options) {
const localBiblio = {};
const baseURL = 'https://github.com/OAI/OpenAPI-Specification/';

md.renderer.rules.link_open = function(tokens, idx, options, env, self) {
if (
idx > 0
&& tokens[idx + 1] && tokens[idx + 1].type === 'text'
&& tokens[idx + 2] && tokens[idx + 2].type === 'link_close'
) {
const text = tokens[idx + 1].content;
// Reference must not contain any whitespace.
const reference = text.replace(/\s+/g, '-');
const url = tokens[idx].attrs[tokens[idx].attrIndex('href')][1];

if (
url.startsWith('http')
&& !url.startsWith(baseURL)
&& !text.includes('RFC')
) {
localBiblio[reference] = {
title: text,
href: url
};

// Do not show url text and closing html tag.
tokens[idx + 1].content = '';
tokens[idx + 2].hidden = true;

return '[[' + reference + ']]';
}
}

return self.renderToken(tokens, idx, options);
};

function preface(title, options, localBublio) {
const respec = {
specStatus: "base",
editors: maintainers,
formerEditors: emeritus,
publishDate: options.publishDate,
subtitle: 'Version '+options.subtitle,
processVersion: 2017,
edDraftURI: "https://github.com/OAI/OpenAPI-Specification/",
edDraftURI: baseURL,
github: {
repoURL: "https://github.com/OAI/OpenAPI-Specification/",
repoURL: baseURL,
branch: "master"
},
shortName: "OAS",
noTOC: false,
lint: false,
additionalCopyrightHolders: "the Linux Foundation",
includePermalinks: true
includePermalinks: true,
localBiblio
};

let preface = `<!DOCTYPE html><html lang="en"><head><meta charset="UTF-8"><title>${md.utils.escapeHtml(title)}</title>`;
Expand Down Expand Up @@ -312,7 +348,7 @@ for (let l in lines) {
lines[l] = (linkTarget ? linkTarget : '') + line;
}

s = preface(`OpenAPI Specification v${argv.subtitle} | Introduction, Definitions, & More`,argv)+'\n\n'+lines.join('\n');
s = preface(`OpenAPI Specification v${argv.subtitle} | Introduction, Definitions, & More`, argv, localBiblio)+'\n\n'+lines.join('\n');
let out = md.render(s);
out = out.replace(/\[([RGB])\]/g,function(match,group1){
console.warn('Fixing',match,group1);
Expand Down