aboutsummaryrefslogtreecommitdiff
path: root/scripts
diff options
context:
space:
mode:
authorShinigami <[email protected]>2022-08-07 04:54:28 +0800
committerGitHub <[email protected]>2022-08-06 20:54:28 +0000
commit51a88634092dbe17985e434572385af4e99d1022 (patch)
tree197d605ffabbd765336de45b610a35437bf35c77 /scripts
parent0668cfe393368f59feffbb0e96540603bc2d8755 (diff)
downloadfaker-51a88634092dbe17985e434572385af4e99d1022.tar.xz
faker-51a88634092dbe17985e434572385af4e99d1022.zip
docs: use vitepress v1 (#993)
Diffstat (limited to 'scripts')
-rw-r--r--scripts/apidoc.ts3
-rw-r--r--scripts/apidoc/signature.ts63
2 files changed, 38 insertions, 28 deletions
diff --git a/scripts/apidoc.ts b/scripts/apidoc.ts
index d519a320..ed6f679f 100644
--- a/scripts/apidoc.ts
+++ b/scripts/apidoc.ts
@@ -2,12 +2,15 @@ import { resolve } from 'path';
import { writeApiPagesIndex } from './apidoc/apiDocsWriter';
import { processDirectMethods } from './apidoc/directMethods';
import { processModuleMethods } from './apidoc/moduleMethods';
+import { initMarkdownRenderer } from './apidoc/signature';
import type { PageIndex } from './apidoc/utils';
import { newTypeDocApp, patchProject, pathOutputDir } from './apidoc/utils';
const pathOutputJson = resolve(pathOutputDir, 'typedoc.json');
async function build(): Promise<void> {
+ await initMarkdownRenderer();
+
const app = newTypeDocApp();
app.bootstrap({
diff --git a/scripts/apidoc/signature.ts b/scripts/apidoc/signature.ts
index dd60a223..ce037988 100644
--- a/scripts/apidoc/signature.ts
+++ b/scripts/apidoc/signature.ts
@@ -1,4 +1,4 @@
-import sanitizeHtml from 'sanitize-html';
+// import sanitizeHtml from 'sanitize-html';
import type {
Comment,
DeclarationReflection,
@@ -10,6 +10,7 @@ import type {
Type,
} from 'typedoc';
import { ReflectionFlag, ReflectionKind } from 'typedoc';
+import type { MarkdownRenderer } from 'vitepress';
import { createMarkdownRenderer } from 'vitepress';
import type {
Method,
@@ -38,40 +39,46 @@ export function toBlock(comment?: Comment): string {
return joinTagParts(comment?.summary) || 'Missing';
}
-const markdown = createMarkdownRenderer(
- pathOutputDir,
- vitepressConfig.markdown,
- '/'
-);
-
-const htmlSanitizeOptions: sanitizeHtml.IOptions = {
- allowedTags: ['a', 'code', 'div', 'li', 'span', 'p', 'pre', 'ul'],
- allowedAttributes: {
- a: ['href', 'target', 'rel'],
- div: ['class'],
- pre: ['v-pre'],
- span: ['class'],
- },
- selfClosing: [],
-};
+let markdown: MarkdownRenderer;
+
+export async function initMarkdownRenderer(): Promise<void> {
+ markdown = await createMarkdownRenderer(
+ pathOutputDir,
+ vitepressConfig.markdown,
+ '/'
+ );
+}
+
+// const htmlSanitizeOptions: sanitizeHtml.IOptions = {
+// allowedTags: ['a', 'code', 'div', 'li', 'span', 'p', 'pre', 'ul'],
+// allowedAttributes: {
+// a: ['href', 'target', 'rel'],
+// div: ['class'],
+// pre: ['v-pre'],
+// span: ['class'],
+// },
+// selfClosing: [],
+// };
function mdToHtml(md: string): string {
const rawHtml = markdown.render(md);
- const safeHtml: string = sanitizeHtml(rawHtml, htmlSanitizeOptions);
- // Revert some escaped characters for comparison.
- if (rawHtml.replace(/&gt;/g, '>') === safeHtml.replace(/&gt;/g, '>')) {
- return safeHtml;
- } else {
- console.debug('Rejected unsafe md:', md);
- console.error('Rejected unsafe html:', rawHtml.replace(/&gt;/g, '>'));
- console.error('Expected safe html:', safeHtml.replace(/&gt;/g, '>'));
- throw new Error('Found unsafe html');
- }
+ // TODO @Shinigami92 2022-06-24: Sanitize html to prevent XSS
+ return rawHtml;
+ // const safeHtml: string = sanitizeHtml(rawHtml, htmlSanitizeOptions);
+ // // Revert some escaped characters for comparison.
+ // if (rawHtml.replace(/&gt;/g, '>') === safeHtml.replace(/&gt;/g, '>')) {
+ // return safeHtml;
+ // } else {
+ // console.debug('Rejected unsafe md:', md);
+ // console.error('Rejected unsafe html:', rawHtml.replace(/&gt;/g, '>'));
+ // console.error('Expected safe html:', safeHtml.replace(/&gt;/g, '>'));
+ // throw new Error('Found unsafe html');
+ // }
}
export function analyzeSignature(
signature: SignatureReflection,
- moduleName: string,
+ moduleName: string | null,
methodName: string
): Method {
const parameters: MethodParameter[] = [];