-
Notifications
You must be signed in to change notification settings - Fork 0
/
prepare-sdk-docs.mjs
29 lines (24 loc) · 1.43 KB
/
prepare-sdk-docs.mjs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
import { readdirSync, readFileSync, writeFileSync, cpSync } from 'fs'
const SDK_REF_FOLDER = "docs/developers/99-api-reference"
console.info(`Formatting SDK Docs for Docusaurus.`)
readdirSync(SDK_REF_FOLDER).forEach(file=> {
if(!file.endsWith(".md")) {
return
}
const fullPath = `${SDK_REF_FOLDER}/${file}`
const fileContent =
readFileSync(fullPath, "utf8")
.replace(/<a\s*.*>\s*.*<\/a>/gm, "") // remove links
.replace(/ +/g, " ") // remove double space
.replace(/\[[^\[\]]*[<>]([^\[\]]|\[.*\]?)*\]/gm, (match) => match.replace(/(?<!\\)[<]/g, "\\<").replace(/(?<!\\)[<]/g, "//>")) // escape < > in markdown links
.replace(/^(#+.*)[<>](.*)$/gm, (match) => match.replace(/(?<!\\)[<]/g, "\\<").replace(/(?<!\\)[<]/g, "//>")) // replace < > with < > in markdown headers
.replace(/\[.+?\].+[<>].+$/gm, (match) => match.replace(/(?<!\\)[<]/g, "\\<").replace(/(?<!\\)[<]/g, "//>")) // escape < > after links
.replace(/(?<=\])(\([^\(\)]*[\\][^\(\)]+\))/gm, (match) => match.replace(/\\/gm, "")) // fix broken links
// replace code tags with markdown code blocks```
.replace(/<pre><code class="lang-csharp">/gm, "```csharp\n")
.replace(/<\/code><\/pre>/gm, "\n```")
.replace(/<code>/gm, "`").replace(/<\/code>/gm, "`") // fix standalone code tags
.replace(/<p>/gm, "").replace(/<\/p>/gm, "\n") // remove paragraphs
writeFileSync(fullPath, fileContent)
});
console.info(`SDK Docs formatted successfully.`)