Skip to content

Commit

Permalink
fix(core): display all available markdown content for index html tables
Browse files Browse the repository at this point in the history
  • Loading branch information
tgreyuk committed Jul 5, 2024
1 parent 5e8b1e6 commit b710dc9
Show file tree
Hide file tree
Showing 9 changed files with 1,042 additions and 183 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -573,7 +573,7 @@ This option renders index items either as a simple unordered list or in a table.

When table style is selected the following will be the behaviour:

* For a **members index**, a description column will be added to the table with the first paragraph of the comment summary.
* For a **members index**, a description column will be added with key `table` - the first paragraph of the comment summary, or key `htmlTable` - the entire comment contents.
* For a **packages index**, (when `--entryPointStrategy` equals `packages`), the package.json description will be displayed with an additional "Version" column (when `--includeVersion` equals true).
* For a **documents index** a description column will be added to the table printing the `"description"` frontmatter variable.

Expand Down
6 changes: 3 additions & 3 deletions docs/pages/docs/options/display-options.mdx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Callout, FileTree } from 'nextra/components';
import { Callout, FileTree } from "nextra/components";

# Display Options

Expand Down Expand Up @@ -136,13 +136,13 @@ Use this option to preserve the position of the tag content with the comment sum

<Callout emoji="💡">Sets the format of index items.</Callout>

> Accepts one of `"list"` | `"table"`. Defaults to `"list"`.
> Accepts one of `"list"` | `"table"` | `"htmlTable"`. Defaults to `"list"`.
This option renders index items either as a simple unordered list or in a table.

When table style is selected the following will be the behaviour:

- For a **members index**, a description column will be added to the table with the first paragraph of the comment summary.
- For a **members index**, a description column will be added with key `table` - the first paragraph of the comment summary, or key `htmlTable` - the entire comment contents.
- For a **packages index**, (when `--entryPointStrategy` equals `packages`), the package.json description will be displayed with an additional "Version" column (when `--includeVersion` equals true).
- For a **documents index** a description column will be added to the table printing the `"description"` frontmatter variable.

Expand Down
55 changes: 45 additions & 10 deletions docs/public/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,11 @@
},
"classPropertiesFormat": {
"type": "string",
"enum": ["list", "table", "htmlTable"],
"enum": [
"list",
"table",
"htmlTable"
],
"description": "[typedoc-plugin-markdown] Sets the format of property groups for classes.",
"default": "list"
},
Expand All @@ -36,7 +40,11 @@
},
"enumMembersFormat": {
"type": "string",
"enum": ["list", "table", "htmlTable"],
"enum": [
"list",
"table",
"htmlTable"
],
"description": "[typedoc-plugin-markdown] Sets the format of enumeration members.",
"default": "list"
},
Expand Down Expand Up @@ -84,13 +92,21 @@
},
"indexFormat": {
"type": "string",
"enum": ["list", "table"],
"enum": [
"list",
"table",
"htmlTable"
],
"description": "[typedoc-plugin-markdown] Sets the format of index items.",
"default": "list"
},
"interfacePropertiesFormat": {
"type": "string",
"enum": ["list", "table", "htmlTable"],
"enum": [
"list",
"table",
"htmlTable"
],
"description": "[typedoc-plugin-markdown] Sets the format of property groups for interfaces.",
"default": "list"
},
Expand Down Expand Up @@ -143,13 +159,20 @@
},
"outputFileStrategy": {
"type": "string",
"enum": ["members", "modules"],
"enum": [
"members",
"modules"
],
"description": "[typedoc-plugin-markdown] Determines how output files are generated.",
"default": "members"
},
"parametersFormat": {
"type": "string",
"enum": ["list", "table", "htmlTable"],
"enum": [
"list",
"table",
"htmlTable"
],
"description": "[typedoc-plugin-markdown] Sets the format of parameter and type parameter groups.",
"default": "list"
},
Expand All @@ -159,13 +182,21 @@
},
"propertiesFormat": {
"type": "string",
"enum": ["list", "table", "htmlTable"],
"enum": [
"list",
"table",
"htmlTable"
],
"description": "[typedoc-plugin-markdown] Sets the format of property groups for interfaces and classes.",
"default": "list"
},
"propertyMembersFormat": {
"type": "string",
"enum": ["list", "table", "htmlTable"],
"enum": [
"list",
"table",
"htmlTable"
],
"description": "[typedoc-plugin-markdown] Sets the format of style for property members for interfaces and classes.",
"default": "list"
},
Expand Down Expand Up @@ -247,7 +278,11 @@
},
"typeDeclarationFormat": {
"type": "string",
"enum": ["list", "table", "htmlTable"],
"enum": [
"list",
"table",
"htmlTable"
],
"description": "[typedoc-plugin-markdown] Sets the format of style for type declaration members.",
"default": "list"
},
Expand All @@ -268,4 +303,4 @@
"definitions": {}
}
]
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -367,7 +367,7 @@ export const blockTagsPreserveOrder: Partial<DeclarationOption> = {
*
* When table style is selected the following will be the behaviour:
*
* - For a **members index**, a description column will be added to the table with the first paragraph of the comment summary.
* - For a **members index**, a description column will be added with key `table` - the first paragraph of the comment summary, or key `htmlTable` - the entire comment contents.
* - For a **packages index**, (when `--entryPointStrategy` equals `packages`), the package.json description will be displayed with an additional "Version" column (when `--includeVersion` equals true).
* - For a **documents index** a description column will be added to the table printing the `"description"` frontmatter variable.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export function getDescriptionForReflection(
if (comment?.summary?.length) {
return this.helpers
.getCommentParts(comment.summary)
?.split('\n\n')[0]
?.split(/(\r?\n){2}/)[0]
.replace(/\r?\n/g, ' ');
}
return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ export function getGroupIndexTable(
'tableColumnSettings',
).leftAlignHeaders;

const isHtmlTable = this.options.getValue('indexFormat') === 'htmlTable';

const childKindStrings = children.map((child) =>
ReflectionKind.singularString(child.kind),
);
Expand All @@ -29,16 +31,27 @@ export function getGroupIndexTable(
if (child.url) {
row.push(link(escapeChars(child.name), this.getRelativeUrl(child.url)));
}
const description =
child instanceof DeclarationReflection
? this.helpers.getDescriptionForReflection(child)
: ((child as DocumentReflection).frontmatter.description as string);
row.push(description || '-');

const description = () => {
if (child instanceof DocumentReflection) {
return child.frontmatter.description as string;
}
if (!child.comment) {
return '';
}
return isHtmlTable
? this.partials.comment(child.comment, {
isTableColumn: true,
})
: this.helpers.getDescriptionForReflection(child);
};

row.push(description() || '-');

rows.push(row);
});

return this.options.getValue('indexFormat') === 'htmlTable'
return isHtmlTable
? htmlTable(headers, rows, leftAlignHeadings)
: table(headers, rows, leftAlignHeadings);
}
3 changes: 2 additions & 1 deletion packages/typedoc-plugin-markdown/test/fixtures/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ const config: Record<string, Fixture> = {
navigationModel: {
excludeGroups: true,
},
indexFormat: 'table',
},
{
readme: 'none',
Expand All @@ -120,7 +121,7 @@ const config: Record<string, Fixture> = {
],
hideGroupHeadings: true,
useHTMLAnchors: true,
indexFormat: 'table',
indexFormat: 'htmlTable',
categorizeByGroup: false,
},
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,14 @@
* and comments on a soft line.
*
* Comments on double new line.
*
* ```typescript
* const a = new InterfaceA();
* ```
*
* @remarks
*
* Block tag content.
*/
export interface InterfaceA {
propA: string;
Expand Down
Loading

0 comments on commit b710dc9

Please sign in to comment.