Skip to content

Commit

Permalink
Merge pull request #4033 from ralfhandl/main-script-tweaks
Browse files Browse the repository at this point in the history
build script: example links point to HTML wrapper on learn site
  • Loading branch information
lornajane authored Aug 22, 2024
2 parents f8114db + 3c2c9c6 commit c754de0
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 8 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"license": "Apache-2.0",
"scripts": {
"build": "bash ./scripts/md2html/build.sh",
"test": "c8 vitest --watch=false"
"test": "c8 --100 vitest --watch=false"
},
"readmeFilename": "README.md",
"files": [
Expand Down
8 changes: 5 additions & 3 deletions scripts/md2html/md2html.js
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ for (let l in lines) {

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

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

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

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

// fix relative links (to examples)
if (!inCodeBlock && line.indexOf('](../examples/') >= 0) {
// links to examples go to learn site, links to yaml files go to wrapper html
line = line.replace(/\(\.\.\/examples\/([^)]+)\)/g,function(match,group1){
console.warn("example link",group1);
//TODO: group1 = group1.replace('.yaml','.html');
group1 = group1.replace('.yaml','.html');
return `(https://learn.openapis.org/examples/${group1})`;
})
} else if (!inCodeBlock && line.indexOf('](../') >= 0) {
// links to other sibling files go to github
const regExp = /\((\.\.[^)]+)\)/g;
line = line.replace(regExp,function(match,group1){
console.warn('relative link',group1);
Expand Down
2 changes: 1 addition & 1 deletion tests/md2html/fixtures/basic-new.html
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
<p>Definition of Foo.</p>
</section></section><section><h1>Another Heading 2</h1>
<p>Text for second section</p>
<p><a href="https://learn.openapis.org/examples/foo.yaml">Relative link to example</a></p>
<p><a href="https://learn.openapis.org/examples/foo.html">Relative link to example</a></p>
<p><a href="https://github.com/OAI/OpenAPI-Specification/tree/main/something/else">Relative link to something else</a></p>
<section><h2>Heading 3</h2>
<p>Text for first subsection</p>
Expand Down
1 change: 0 additions & 1 deletion tests/md2html/fixtures/basic-old.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
<p>Text for first chapter</p>
<section class="override" id="conformance"><h2>Version 30.0.1</h2>
<p>This is the conformance section</p>
<!-- /TOC -->
</section></section><section><h1>Heading 2</h1>
<p>Text for first section</p>
<p><span id="parameterAllowEmptyValue"></span>Broken anchor</p>
Expand Down
2 changes: 0 additions & 2 deletions tests/md2html/fixtures/basic-old.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@ This is the conformance section

Will be removed

<!-- /TOC -->

## Heading 2

Text for first section
Expand Down
7 changes: 7 additions & 0 deletions vitest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { defineConfig } from 'vitest/config'

export default defineConfig({
test: {
forceRerunTriggers: ['**/scripts/**', '**/tests/**'],
},
})

0 comments on commit c754de0

Please sign in to comment.