Skip to content

Commit

Permalink
fix(core): fix display of index descriptions in tables
Browse files Browse the repository at this point in the history
  • Loading branch information
tgreyuk committed May 17, 2024
1 parent 4fa4093 commit 16712a4
Show file tree
Hide file tree
Showing 10 changed files with 313 additions and 169 deletions.
3 changes: 2 additions & 1 deletion .changeset/yellow-beds-smile.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
---
"typedoc-plugin-markdown": patch
'typedoc-plugin-markdown': patch
---

- Remove superfluous quotes from prop names (#619)
- Fix display of index descriptions in tables (#619)
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,5 @@ export function getDeclarationComment(model: DeclarationReflection) {
if (model.signatures?.length) {
return model.signatures[0].comment;
}
if ((model.type as any)?.declaration?.signatures?.length) {
return (model.type as any)?.declaration.signatures[0].comment;
}
return model.comment;
}
Original file line number Diff line number Diff line change
Expand Up @@ -596,7 +596,7 @@ There is no association list partial for properties as these are handled as a st
export const helpers = (context: MarkdownThemeContext) => {
return {
getDeclarationComment: (model: DeclarationReflection) =>
getDeclarationComment.apply(context, [model]) as any,
getDeclarationComment.apply(context, [model]) as Comment | undefined,
getDeclarationType: (model: DeclarationReflection) =>
getDeclarationType.apply(context, [model]) as SomeType | undefined,
getFlattenedDeclarations: (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,12 @@ function getTable(
const comment = context.helpers.getDeclarationComment(child);

if (comment?.summary?.length) {
row.push(context.partials.commentParts(comment.summary)?.split('\n')[0]);
row.push(
context.partials
.commentParts(comment.summary)
?.split('\n\n')[0]
.replace(/\n/g, ' '),
);
} else {
row.push('-');
}
Expand Down
14 changes: 12 additions & 2 deletions packages/typedoc-plugin-markdown/test/fixtures/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,11 @@ const config: Record<string, Fixture> = {
only: false,
entryPoints: '/groups/**/*.ts',
commonOptions: {
plugin: [path.join(__dirname, 'custom-plugins', 'navigation-plugin.mjs')],
plugin: [
path.join(__dirname, 'custom-plugins', 'stub-groups-theme.mjs'),
path.join(__dirname, 'custom-plugins', 'navigation-plugin.mjs'),
],
theme: 'stub-groups',
disableSources: true,
entryFileName: 'index.md',
},
Expand All @@ -89,7 +93,13 @@ const config: Record<string, Fixture> = {
},
{
readme: 'none',
membersWithOwnFile: ['Class', 'Interface', 'Enum'],
membersWithOwnFile: [
'Class',
'Interface',
'Enum',
'TypeAlias',
'Function',
],
excludeGroups: true,
useHTMLAnchors: true,
indexFormat: 'table',
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
// @ts-check
import { MarkdownTheme, MarkdownThemeContext } from 'typedoc-plugin-markdown';

/**
* @param {import('typedoc-plugin-markdown').MarkdownApplication} app
*/
export function load(app) {
app.renderer.defineTheme('stub-groups', StubPartialsTheme);
}

class StubPartialsTheme extends MarkdownTheme {
/**
* @param {import('typedoc-plugin-markdown').MarkdownPageEvent} page
*/
getRenderContext(page) {
return new MyMarkdownThemeContext(this, page, this.application.options);
}
}

class MyMarkdownThemeContext extends MarkdownThemeContext {
partials = {
...this.partials,
declaration: () => {
return `_DECLARATION_MEMBER_PARTIAL_`;
},
signature: () => {
return `_SIGNATURE_MEMBER_PARTIAL_`;
},
};
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,46 @@
*
* @module
*/

/**
* Interface A comments line 1
* and comments on a soft line.
*
* Comments on double new line.
*/
export interface InterfaceA {
propA: string;
propB: string;
}

/**
* InterfaceB function.
*/
export interface InterfaceB {}
/**
* EnumA function.
*/
export enum EnumA {}
export enum EnumB {}
/**
* ClassA function.
*/
export class ClassA {}
export class ClassB {}
/**
* TypeA function.
*/
export type TypeA = string;
export type TypeB = string;
/**
* TypeB function.
*
* @param str - A string to tokenize.
* @param offset - Initial offset. Used when composing lexers.
*/
export type TypeB = (str: string, offset?: number) => any;
/**
* functionA function.
*/
export function functionA() {}
export const variableA = '';
export const variableB = '';

0 comments on commit 16712a4

Please sign in to comment.