Skip to content

Commit

Permalink
feat(core): improved tables functionality
Browse files Browse the repository at this point in the history
  • Loading branch information
tgreyuk committed May 17, 2024
1 parent 96afe71 commit b039203
Show file tree
Hide file tree
Showing 39 changed files with 713 additions and 617 deletions.
3 changes: 2 additions & 1 deletion devtools/examples/docusaurus/docusaurus.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,8 @@ const config = {
expandObjects: true,
readme: 'none',
sidebar: { pretty: true },
outputFileStrategy: 'modules',
outputFileStrategy: 'members',
propertiesFormat: 'htmlTable',
cleanOutputDir: true,
},
],
Expand Down
1 change: 0 additions & 1 deletion devtools/packages/fixtures/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,6 @@ function writeMarkdown(
path.join(__dirname, 'typedoc.cjs'),
'-logLevel',
'Warn',

'-out',
fullPath,
],
Expand Down
1 change: 1 addition & 0 deletions devtools/packages/prebuild-options/tasks/generate-docs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@ ${presetsJson}
meta.push(type);
}
if (
option.type !== ParameterType.Flags &&
option.type !== ParameterType.Array &&
option.type !== ParameterType.Mixed
) {
Expand Down
39 changes: 33 additions & 6 deletions docs/pages/docs/options.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -395,7 +395,7 @@ This option should be set when a full type representation is preferred.
Specify the render style of parameter and type parameter groups.
</Callout>

> Accepts either `"list"` or `"table"`. Defaults to `"list"`.
> Accepts one of `"list"` | `"table"` | `"htmlTable"`. Defaults to `"list"`.
This option either renders parameters for functions and class methods as a list or in tabular format.

Expand All @@ -413,7 +413,7 @@ This option either renders parameters for functions and class methods as a list
Specify the render style of property groups for interfaces and classes.
</Callout>

> Accepts either `"list"` or `"table"`. Defaults to `"list"`.
> Accepts one of `"list"` | `"table"` | `"htmlTable"`. Defaults to `"list"`.
This option either renders properties for classes and interfaces as a list or in tabular format.

Expand All @@ -429,7 +429,7 @@ This option either renders properties for classes and interfaces as a list or in

<Callout emoji="💡">Specify the render style of enumeration members.</Callout>

> Accepts either `"list"` or `"table"`. Defaults to `"list"`.
> Accepts one of `"list"` | `"table"` | `"htmlTable"`. Defaults to `"list"`.
This option either renders members of enums as a list or in tabular format.

Expand All @@ -447,7 +447,7 @@ This option either renders members of enums as a list or in tabular format.
Specify the render style for type declaration members.
</Callout>

> Accepts either `"list"` or `"table"`. Defaults to `"list"`.
> Accepts one of `"list"` | `"table"` | `"htmlTable"`. Defaults to `"list"`.
This option either renders type declarations as a list or in tabular format.

Expand All @@ -463,7 +463,7 @@ This option either renders type declarations as a list or in tabular format.

<Callout emoji="💡">Specify the render format for index items.</Callout>

> Accepts either `"list"` or `"table"`. Defaults to `"list"`.
> Accepts one of `"list"` | `"table"` | `"htmlTable"`. Defaults to `"list"`.
This option renders index items either as a simple list or in a table with a description column exposing the comment summary.

Expand All @@ -477,6 +477,33 @@ For a packages index page (when `--entryPointStrategy` equals `packages`), the p

---

### tableColumns

<Callout emoji="💡">
Control header alignment and column visibility in tables.
</Callout>

>
By default, all available data for symbols are displayed in columns, which can result in very large tables.

This option allows you to control the visibility of columns, prioritizing readability over displaying complete data.

```json filename="typedoc.json"
{
"tableColumns": {
"excludeDefaultsCol": false,
"excludeInheritedFromCol": false,
"excludeModifiersCol": false,
"excludeOverridesCol": false,
"excludeSourcesCol": false,
"leftAlignHeadings": false
}
}
```

---

### textContentMappings

<Callout emoji="💡">
Expand Down Expand Up @@ -693,7 +720,7 @@ This option can be used for engines that require the preservation of anchor link
Configures how the navigation model will be generated.
</Callout>

> Defaults to `{"excludeGroups":false,"excludeCategories":false,"excludeFolders":false}`.
>
By default navigation is not written to file but can be consumed programmatically. Please see [Navigation Guide](/docs/navigation) for more information.

Expand Down
26 changes: 26 additions & 0 deletions packages/typedoc-plugin-markdown/src/libs/markdown/html-table.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
export function htmlTable(
headers: string[],
rows: string[][],
leftAlignHeadings = false,
) {
return `<table>
<tr>${headers.map((header) => `<th${leftAlignHeadings ? ' align="left"' : ''}>${header}</th>`).join('')}</tr>${rows
.map(
(row) =>
`
<tr>${row
.map(
(cell) =>
`
<td>
${cell === '-' ? '&hyphen;' : cell}
</td>`,
)
.join('')}
</tr>`,
)
.join('')}
</table>`;
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ export { bold } from './bold';
export { codeBlock } from './code-block';
export { heading } from './heading';
export { horizontalRule } from './horizontal-rule';
export { htmlTable } from './html-table';
export { indentBlock } from './indent-block';
export { italic } from './italic';
export { link } from './link';
Expand Down
13 changes: 10 additions & 3 deletions packages/typedoc-plugin-markdown/src/libs/markdown/table.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,17 @@
import { formatTableCell } from '../utils/format-table-cell';
/**
* Comments for table
* @param headers
* @param rows
*/
export function table(headers: string[], rows: string[][]) {
export function table(
headers: string[],
rows: string[][],
headerLeftAlign = false,
) {
return `\n| ${headers.join(' | ')} |\n| ${headers
.map(() => ':------')
.join(' | ')} |\n${rows.map((row) => `| ${row.join(' | ')} |\n`).join('')}`;
.map(() => `${headerLeftAlign ? ':' : ''}------`)
.join(
' | ',
)} |\n${rows.map((row) => `| ${row.map((cell) => formatTableCell(cell)).join(' | ')} |\n`).join('')}`;
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { formatTableCell } from './format-table-cell';

describe('formatTableCell', () => {
it('should correctly format the cell content', () => {
const input = `
This is a test
\`\`\`ts
const x = 10;
\`\`\`
with multiple spaces.
`;
const expectedOutput =
'This is a test `const x = 10;` with multiple spaces.';
expect(formatTableCell(input)).toBe(expectedOutput);
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
/**
* - Replace new lines with spaces
* - Replaces code blocks with single backticks
* - Replaces multiple spaces with single spaces
*/
export function formatTableCell(str: string) {
return str
.replace(/\n/g, ' ')
.replace(
/```(\w+\s)?([\s\S]*?)```/gs,
(match, p1, p2) => `\`${p2.trim()}\``,
)
.replace(/ +/g, ' ')
.trim();
}

This file was deleted.

This file was deleted.

3 changes: 1 addition & 2 deletions packages/typedoc-plugin-markdown/src/libs/utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,9 @@
export { camelToTitleCase } from './camel-to-title-case';
export { escapeChars } from './escape-chars';
export { formatMarkdown } from './format-markdown';
export { formatTableColumn } from './format-table-column';
export { formatTableCell } from './format-table-cell';
export { getFileNameWithExtension } from './get-file-name-with-extension';
export { isQuoted } from './is-quoted';
export { markdownBlocksToHtml } from './markdown-blocks-to-html';
export { normalizeLineBreaks } from './normalize-line-breaks';
export { removeFirstScopedDirectory } from './remove-first-scoped-directory';
export { removeLineBreaks } from './remove-line-breaks';
Expand Down

This file was deleted.

This file was deleted.

0 comments on commit b039203

Please sign in to comment.