From bd18fd1f86d7c9ef42e862c6a6e4dff006068ed9 Mon Sep 17 00:00:00 2001 From: ST-DDT Date: Fri, 28 Jan 2022 23:04:10 +0100 Subject: [PATCH] docs: use html tables instead of md tables to account for ::: v-pre (#330) Co-authored-by: Jessica Sachs Co-authored-by: Shinigami --- docs/.vitepress/theme/index.css | 3 ++ docs/.vitepress/theme/index.mjs | 1 + scripts/apidoc.ts | 63 ++++++++++++++++++++++----------- 3 files changed, 46 insertions(+), 21 deletions(-) create mode 100644 docs/.vitepress/theme/index.css diff --git a/docs/.vitepress/theme/index.css b/docs/.vitepress/theme/index.css new file mode 100644 index 00000000000..21bbf49454b --- /dev/null +++ b/docs/.vitepress/theme/index.css @@ -0,0 +1,3 @@ +table td * { + display: inline; +} diff --git a/docs/.vitepress/theme/index.mjs b/docs/.vitepress/theme/index.mjs index 26a6b5caf75..b6bfbb86097 100644 --- a/docs/.vitepress/theme/index.mjs +++ b/docs/.vitepress/theme/index.mjs @@ -1,3 +1,4 @@ +import './index.css'; import GlobalComponents from './components'; import DefaultTheme from 'vitepress/theme'; diff --git a/scripts/apidoc.ts b/scripts/apidoc.ts index 62fc9ed5762..e2b0d36abce 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';