Skip to content

Commit 64b26ac

Browse files
author
Gianluca Beil
committed
Features
1 parent a1fa015 commit 64b26ac

4 files changed

Lines changed: 32 additions & 49 deletions

File tree

internal/documentation/jsdoc-to-markdown.js

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,16 @@ async function htmlToMarkdown(options = {}) {
7676
const excludedFiles = {"index.html": "", "global.html": "", "custom.css": ""};
7777
const inputDirectory = path.join("dist", "api");
7878
const outputDirectory = path.join("docs", "api");
79+
let packageTagName = "https://github.com/UI5/cli/blob/main/packages/";
7980

81+
// 1. Find tag name
82+
if (process.argv[2] == "gh-pages") {
83+
// Read package.json of packages/builder
84+
const builderJson = JSON.parse(fs.readFileSync("tmp/packages/@ui5/builder/package.json"));
85+
packageTagName = `https://github.com/UI5/cli/blob/cli-v${builderJson["version"]}/packages/`;
86+
}
87+
88+
// 2. Check and create api directory, also remove all existing files if it exists
8089
if (!fs.existsSync(outputDirectory)) {
8190
fs.mkdirSync(outputDirectory);
8291
} else {
@@ -85,19 +94,37 @@ if (!fs.existsSync(outputDirectory)) {
8594
}
8695
}
8796

97+
// 3. Iterate through every .html generated by jsdoc
8898
for (const file of fs.readdirSync(path.join("dist", "api"))) {
99+
// Skip js files
89100
if (excludedFiles[file] !== undefined) continue;
101+
90102
const filePath = path.join(inputDirectory, file);
103+
// Skip directories
91104
if (fs.statSync(filePath).isDirectory()) continue;
105+
106+
// Read the html file
92107
const htmlString = fs.readFileSync(filePath);
108+
109+
// Convert html to markdown
93110
let markdown = await htmlToMarkdown({
94111
html: htmlString
95112
});
113+
114+
// Escape characters in markdown
96115
markdown = escapeMarkdown(markdown);
116+
117+
// Fix some markdown syntax e.g. <optional> -> Optional
97118
markdown = fixMarkdown(markdown);
98-
if (file.endsWith(".js.html")) {
99-
markdown = markdown.replace("```", "```javascript");
119+
120+
// Point all js links to GitHub
121+
const linkMatches = markdown.matchAll(/\((.*?)\.js.html\)/g);
122+
for (const linkMatch of linkMatches) {
123+
const githubUrl = packageTagName + linkMatch[1].replace(".js.html", "").replaceAll("_", "/").replace("project", "") + ".js";
124+
markdown = markdown.replaceAll(linkMatch[1] + ".js.html#line", githubUrl + "#L").replaceAll(linkMatch[1] + ".js.html", githubUrl);
100125
}
126+
127+
// Save markdown file
101128
fs.writeFileSync(
102129
path.join(outputDirectory, file.replace(".html", ".md")),
103130
markdown

internal/documentation/jsdoc-to-markdown.sh

Lines changed: 0 additions & 24 deletions
This file was deleted.

internal/documentation/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,9 @@
3131
"preview": "vitepress preview --port 8080",
3232
"jsdoc": "npm run jsdoc-generate && npm run jsdoc-to-markdown",
3333
"jsdoc-generate": "jsdoc -c jsdoc/jsdoc-workspace.json -t $(node -p 'path.dirname(require.resolve(\"docdash\"))') ./ || (echo 'Error during JSDoc generation! Check log.' && exit 1)",
34-
"jsdoc-generate-gh-pages": "jsdoc -c jsdoc/jsdoc.json -t $(node -p 'path.dirname(require.resolve(\"docdash\"))') ./ || (echo 'Error during JSDoc generation! Check log.' && exit 1)",
34+
"jsdoc-generate-gh-pages": "jsdoc -c jsdoc/jsdoc.json -t $(node -p 'path.dirname(require.resolve(\"docdash\"))') ./ || (echo 'Error during JSDoc generation! Check log.' && exit 1) && npm run jsdoc-to-markdown-gh-pages",
3535
"jsdoc-to-markdown": "node ./jsdoc-to-markdown.js",
36+
"jsdoc-to-markdown-gh-pages": "node ./jsdoc-to-markdown.js gh-pages",
3637
"generate-cli-doc": "node ./scripts/generateCliDoc.js",
3738
"schema-generate": "node ./scripts/buildSchema.js",
3839
"schema-generate-gh-pages": "node ./scripts/buildSchema.js gh-pages",

package-lock.json

Lines changed: 1 addition & 22 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)