Skip to content

Commit

Permalink
fix(core): allow htmlTable format key for indexes (#618)
Browse files Browse the repository at this point in the history
  • Loading branch information
tgreyuk committed Jul 2, 2024
1 parent a68cd5d commit aece95b
Show file tree
Hide file tree
Showing 8 changed files with 187 additions and 11 deletions.
5 changes: 5 additions & 0 deletions .changeset/violet-mails-design.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'typedoc-plugin-markdown': patch
---

- Allow htmlTable format key for indexes (#618)
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { link, table } from 'libs/markdown';
import { htmlTable, link, table } from 'libs/markdown';
import { escapeChars } from 'libs/utils';
import { MarkdownThemeContext } from 'public-api';
import {
Expand All @@ -10,7 +10,6 @@ import {
export function getGroupIndexTable(
this: MarkdownThemeContext,
children: DeclarationReflection[] | DocumentReflection[],
kind?: ReflectionKind,
) {
const leftAlignHeadings = this.options.getValue(
'tableColumnSettings',
Expand Down Expand Up @@ -38,5 +37,8 @@ export function getGroupIndexTable(

rows.push(row);
});
return table(headers, rows, leftAlignHeadings);

return this.options.getValue('indexFormat') === 'htmlTable'
? htmlTable(headers, rows, leftAlignHeadings)
: table(headers, rows, leftAlignHeadings);
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {
} from 'typedoc';

export function getGroupIndex(group: ReflectionGroup | ReflectionCategory) {
if (this.options.getValue('indexFormat') === 'table') {
if (this.options.getValue('indexFormat').toLowerCase().includes('table')) {
return this.helpers.getGroupIndexTable(
group.children as DeclarationReflection[] | DocumentReflection[],
group instanceof ReflectionGroup ? group.owningReflection?.kind : null,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { heading, link, table } from 'libs/markdown';
import { heading, htmlTable, link, table } from 'libs/markdown';
import { escapeChars, getFileNameWithExtension } from 'libs/utils';
import * as path from 'path';
import { MarkdownThemeContext } from 'theme';
Expand Down Expand Up @@ -27,7 +27,7 @@ export function packagesIndex(
fileExtension,
);

if (this.options.getValue('indexFormat') === 'table') {
if (this.options.getValue('indexFormat').toLowerCase().includes('table')) {
const headers = [this.i18n.theme_name()];
if (includeVersion) {
headers.push(this.i18n.theme_version());
Expand All @@ -53,7 +53,11 @@ export function packagesIndex(

return rows;
});
md.push(table(headers, packageRows || [], leftAlignHeadings));
const output =
this.options.getValue('indexFormat') === 'htmlTable'
? htmlTable(headers, packageRows || [], leftAlignHeadings)
: table(headers, packageRows || [], leftAlignHeadings);
md.push(output);
} else {
const packagesList = model.children?.map((projectPackage) => {
const urlTo = Boolean(projectPackage.readme)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -289,8 +289,7 @@ export const resourceHelpers = (context: MarkdownThemeContext) => {
) => helpers.getGroupIndexList.apply(context, [children]) as string,
getGroupIndexTable: (
children: DeclarationReflection[] | DocumentReflection[],
kind?: ReflectionKind | undefined,
) => helpers.getGroupIndexTable.apply(context, [children, kind]) as string,
) => helpers.getGroupIndexTable.apply(context, [children]) as string,
getGroupIndex: (group: ReflectionCategory | ReflectionGroup) =>
helpers.getGroupIndex.apply(context, [group]) as any,
getHierarchyType: (
Expand Down
2 changes: 1 addition & 1 deletion packages/typedoc-plugin-markdown/test/fixtures/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,7 @@ const config: Record<string, Fixture> = {
options: [
{},
{
indexFormat: 'table',
indexFormat: 'htmlTable',
flattenOutputFiles: true,
},
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -319,6 +319,89 @@ exports[`Documents Project should compile index page for project: (Output File S
"
`;

exports[`Documents Project should compile index page for project: (Output File Strategy "members") (Option Group "2") 1`] = `
"# typedoc-stubs
## Documents
<table>
<tr>
<th>Document</th>
<th>Description</th>
</tr>
<tr>
<td>
[Project Document 1](Document.Project-Document-1.md)
</td>
<td>
A description of the document
</td>
</tr>
<tr>
<td>
[docs/project/PROJECT\\_DOC\\_2](Document.docs.project.PROJECT_DOC_2.md)
</td>
<td>
&hyphen;
</td>
</tr>
<tr>
<td>
[docs/project/PROJECT\\_DOC\\_3](Document.docs.project.PROJECT_DOC_3.md)
</td>
<td>
&hyphen;
</td>
</tr>
</table>
## Modules
<table>
<tr>
<th>Module</th>
<th>Description</th>
</tr>
<tr>
<td>
[ModuleWithDocuments1](ModuleWithDocuments1.md)
</td>
<td>
&hyphen;
</td>
</tr>
<tr>
<td>
[ModuleWithDocuments2](ModuleWithDocuments2.md)
</td>
<td>
&hyphen;
</td>
</tr>
</table>
"
`;

exports[`Documents Project should compile index page for project: (Output File Strategy "modules") (Option Group "1") 1`] = `
"# typedoc-stubs
Expand All @@ -334,3 +417,86 @@ exports[`Documents Project should compile index page for project: (Output File S
- [ModuleWithDocuments2](ModuleWithDocuments2/README.md)
"
`;

exports[`Documents Project should compile index page for project: (Output File Strategy "modules") (Option Group "2") 1`] = `
"# typedoc-stubs
## Documents
<table>
<tr>
<th>Document</th>
<th>Description</th>
</tr>
<tr>
<td>
[Project Document 1](Document.Project-Document-1.md)
</td>
<td>
A description of the document
</td>
</tr>
<tr>
<td>
[docs/project/PROJECT\\_DOC\\_2](Document.docs.project.PROJECT_DOC_2.md)
</td>
<td>
&hyphen;
</td>
</tr>
<tr>
<td>
[docs/project/PROJECT\\_DOC\\_3](Document.docs.project.PROJECT_DOC_3.md)
</td>
<td>
&hyphen;
</td>
</tr>
</table>
## Modules
<table>
<tr>
<th>Module</th>
<th>Description</th>
</tr>
<tr>
<td>
[ModuleWithDocuments1](ModuleWithDocuments1.md)
</td>
<td>
&hyphen;
</td>
</tr>
<tr>
<td>
[ModuleWithDocuments2](ModuleWithDocuments2.md)
</td>
<td>
&hyphen;
</td>
</tr>
</table>
"
`;
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { expectFileToEqual } from '@devtools/testing';
describe(`Documents`, () => {
describe(`Project`, () => {
test(`should compile index page for project`, () => {
expectFileToEqual('documents', ['modules', 'members'], 'README.md', 1);
expectFileToEqual('documents', ['modules', 'members'], 'README.md');
});

test(`should compile a project document`, () => {
Expand Down

0 comments on commit aece95b

Please sign in to comment.