diff options
Diffstat (limited to 'scripts')
| -rw-r--r-- | scripts/apidoc.ts | 3 | ||||
| -rw-r--r-- | scripts/apidoc/signature.ts | 63 |
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(/>/g, '>') === safeHtml.replace(/>/g, '>')) { - return safeHtml; - } else { - console.debug('Rejected unsafe md:', md); - console.error('Rejected unsafe html:', rawHtml.replace(/>/g, '>')); - console.error('Expected safe html:', safeHtml.replace(/>/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(/>/g, '>') === safeHtml.replace(/>/g, '>')) { + // return safeHtml; + // } else { + // console.debug('Rejected unsafe md:', md); + // console.error('Rejected unsafe html:', rawHtml.replace(/>/g, '>')); + // console.error('Expected safe html:', safeHtml.replace(/>/g, '>')); + // throw new Error('Found unsafe html'); + // } } export function analyzeSignature( signature: SignatureReflection, - moduleName: string, + moduleName: string | null, methodName: string ): Method { const parameters: MethodParameter[] = []; |
