Skip to content

Commit

Permalink
docs: use html tables instead of md tables to account for ::: v-pre (#…
Browse files Browse the repository at this point in the history
…330)

Co-authored-by: Jessica Sachs <[email protected]>
Co-authored-by: Shinigami <[email protected]>
  • Loading branch information
3 people authored Jan 28, 2022
1 parent 537f56e commit a717637
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 21 deletions.
3 changes: 3 additions & 0 deletions docs/.vitepress/theme/index.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
table td * {
display: inline;
}
1 change: 1 addition & 0 deletions docs/.vitepress/theme/index.mjs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import './index.css';
import GlobalComponents from './components';
import DefaultTheme from 'vitepress/theme';

Expand Down
63 changes: 42 additions & 21 deletions scripts/apidoc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,14 @@ function toBlock(comment?: TypeDoc.Comment): string {
);
}

function escape(value: string): string {
return value.replace(/\|/g, '\\|').replace(/</g, '\\<').replace(/>/g, '\\>');
// https://stackoverflow.com/a/6234804/6897682
function escapeHtml(unsafe: string): string {
return unsafe
.replace(/&/g, '&amp;')
.replace(/</g, '&lt;')
.replace(/>/g, '&gt;')
.replace(/"/g, '&quot;')
.replace(/'/g, '&#039;');
}

function parameterRow(
Expand All @@ -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,}/, '<br />')
.replace(/\n/, '') +
'|\n'
);
def = def ? `<code>${def}</code>` : '';
return `<tr>
<td>${escapeHtml(name)}</td>
<td>${escapeHtml(type)}</td>
<td>${def}</td>
<td>
::: v-pre
${toBlock(comment)}
:::
</td>
</tr>
`;
}

async function build(): Promise<void> {
Expand Down Expand Up @@ -133,10 +141,19 @@ async function build(): Promise<void> {
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**
<table>
<thead>
<tr>
<th>Name</th>
<th>Type</th>
<th>Default</th>
<th>Description</th>
</tr>
</thead>
<tbody>
`;

// typeParameters
typeParameters.forEach((parameter, index) => {
Expand Down Expand Up @@ -176,7 +193,11 @@ async function build(): Promise<void> {
parameter.comment
);
});
content += '\n\n';

content += ` </tbody>
</table>
`;
}
content += '**Returns:** ' + signature.type.toString() + '\n\n';

Expand Down

0 comments on commit a717637

Please sign in to comment.