From a7176371f61cd2b317947e67d484944332dc4bd6 Mon Sep 17 00:00:00 2001 From: ST-DDT Date: Fri, 28 Jan 2022 23:04:10 +0100 Subject: docs: use html tables instead of md tables to account for ::: v-pre (#330) Co-authored-by: Jessica Sachs Co-authored-by: Shinigami --- scripts/apidoc.ts | 63 ++++++++++++++++++++++++++++++++++++------------------- 1 file changed, 42 insertions(+), 21 deletions(-) (limited to 'scripts') diff --git a/scripts/apidoc.ts b/scripts/apidoc.ts index 62fc9ed5..e2b0d36a 100644 --- a/scripts/apidoc.ts +++ b/scripts/apidoc.ts @@ -20,8 +20,14 @@ function toBlock(comment?: TypeDoc.Comment): string { ); } -function escape(value: string): string { - return value.replace(/\|/g, '\\|').replace(//g, '\\>'); +// https://stackoverflow.com/a/6234804/6897682 +function escapeHtml(unsafe: string): string { + return unsafe + .replace(/&/g, '&') + .replace(//g, '>') + .replace(/"/g, '"') + .replace(/'/g, '''); } function parameterRow( @@ -30,20 +36,22 @@ function parameterRow( def?: string, comment?: TypeDoc.Comment ): string { - def = def ? `\`${def}\`` : ''; - return ( - '| ' + - escape(name) + - ' | ' + - escape(type) + - ' | ' + - def + - ' | ' + - escape(toBlock(comment)) - .replace(/\n{2,}/, '
') - .replace(/\n/, '') + - '|\n' - ); + def = def ? `${def}` : ''; + return ` + ${escapeHtml(name)} + ${escapeHtml(type)} + ${def} + + +::: v-pre + +${toBlock(comment)} + +::: + + + +`; } async function build(): Promise { @@ -133,10 +141,19 @@ async function build(): Promise { const signatureParameters: string[] = []; let requiresArgs = false; if (typeParameters.length !== 0 || parameters.length !== 0) { - content += `**Parameters**\n\n`; - - content += '| Name | Type | Default | Description |\n'; - content += '| ---- | ---- | ------- | ----------- |\n'; + content += `**Parameters** + + + + + + + + + + + +`; // typeParameters typeParameters.forEach((parameter, index) => { @@ -176,7 +193,11 @@ async function build(): Promise { parameter.comment ); }); - content += '\n\n'; + + content += ` +
NameTypeDefaultDescription
+ +`; } content += '**Returns:** ' + signature.type.toString() + '\n\n'; -- cgit v1.2.3