Skip to content

Commit c754de0

Browse files
authored
Merge pull request #4033 from ralfhandl/main-script-tweaks
build script: example links point to HTML wrapper on learn site
2 parents f8114db + 3c2c9c6 commit c754de0

File tree

6 files changed

+14
-8
lines changed

6 files changed

+14
-8
lines changed

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
"license": "Apache-2.0",
1515
"scripts": {
1616
"build": "bash ./scripts/md2html/build.sh",
17-
"test": "c8 vitest --watch=false"
17+
"test": "c8 --100 vitest --watch=false"
1818
},
1919
"readmeFilename": "README.md",
2020
"files": [

scripts/md2html/md2html.js

+5-3
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,7 @@ for (let l in lines) {
190190

191191
// remove TOC from older spec versions, respec will generate a new one
192192
if (line.startsWith('## Table of Contents')) inTOC = true;
193-
if (line.startsWith('<!-- /TOC')) inTOC = false;
193+
else if (line.startsWith('#')) inTOC = false;
194194
if (inTOC) line = '';
195195

196196
// special formatting for Definitions section
@@ -209,7 +209,7 @@ for (let l in lines) {
209209
line = line.replace('<a name="parameterAllowEmptyValue"/>','<span id="parameterAllowEmptyValue"></span>');
210210
}
211211

212-
// replace deprecated <a name="..."></a> with <span id="..."></span>
212+
// replace deprecated <a name="..."></a> with <span id="..."></span> - needed for older specs
213213
line = line.replace(/<a name="([^"]+)"><\/a>/g,'<span id="$1"></span>');
214214

215215
line = line.split('\\|').join('&#124;'); // was &brvbar
@@ -271,12 +271,14 @@ for (let l in lines) {
271271

272272
// fix relative links (to examples)
273273
if (!inCodeBlock && line.indexOf('](../examples/') >= 0) {
274+
// links to examples go to learn site, links to yaml files go to wrapper html
274275
line = line.replace(/\(\.\.\/examples\/([^)]+)\)/g,function(match,group1){
275276
console.warn("example link",group1);
276-
//TODO: group1 = group1.replace('.yaml','.html');
277+
group1 = group1.replace('.yaml','.html');
277278
return `(https://learn.openapis.org/examples/${group1})`;
278279
})
279280
} else if (!inCodeBlock && line.indexOf('](../') >= 0) {
281+
// links to other sibling files go to github
280282
const regExp = /\((\.\.[^)]+)\)/g;
281283
line = line.replace(regExp,function(match,group1){
282284
console.warn('relative link',group1);

tests/md2html/fixtures/basic-new.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
<p>Definition of Foo.</p>
1111
</section></section><section><h1>Another Heading 2</h1>
1212
<p>Text for second section</p>
13-
<p><a href="https://learn.openapis.org/examples/foo.yaml">Relative link to example</a></p>
13+
<p><a href="https://learn.openapis.org/examples/foo.html">Relative link to example</a></p>
1414
<p><a href="https://github.com/OAI/OpenAPI-Specification/tree/main/something/else">Relative link to something else</a></p>
1515
<section><h2>Heading 3</h2>
1616
<p>Text for first subsection</p>

tests/md2html/fixtures/basic-old.html

-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
<p>Text for first chapter</p>
44
<section class="override" id="conformance"><h2>Version 30.0.1</h2>
55
<p>This is the conformance section</p>
6-
<!-- /TOC -->
76
</section></section><section><h1>Heading 2</h1>
87
<p>Text for first section</p>
98
<p><span id="parameterAllowEmptyValue"></span>Broken anchor</p>

tests/md2html/fixtures/basic-old.md

-2
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,6 @@ This is the conformance section
1010

1111
Will be removed
1212

13-
<!-- /TOC -->
14-
1513
## Heading 2
1614

1715
Text for first section

vitest.config.js

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import { defineConfig } from 'vitest/config'
2+
3+
export default defineConfig({
4+
test: {
5+
forceRerunTriggers: ['**/scripts/**', '**/tests/**'],
6+
},
7+
})

0 commit comments

Comments
 (0)