Skip to content

Commit

Permalink
fix: Tweak typeparams in page title
Browse files Browse the repository at this point in the history
  • Loading branch information
tgreyuk committed May 2, 2023
1 parent 1856797 commit db5ebc3
Show file tree
Hide file tree
Showing 9 changed files with 33 additions and 36 deletions.
1 change: 0 additions & 1 deletion packages/docusaurus-plugin-typedoc/src/options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ const DEFAULT_PLUGIN_OPTIONS: Partial<PluginOptions> = {
hideBreadcrumbs: true,
entryDocument: 'index.md',
watch: false,
enableFrontmatter: true,
numberPrefixOutput: true,
};

Expand Down
22 changes: 22 additions & 0 deletions packages/typedoc-plugin-markdown/src/partials/member.title.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { DeclarationReflection } from 'typedoc';
import { backTicks } from '../support/els';
import { escapeChars } from '../support/utils';
import { MarkdownThemeRenderContext } from '../theme-render-context';

export function memberTitle(
context: MarkdownThemeRenderContext,
reflection: DeclarationReflection,
typeParams = false,
) {
const md = [escapeChars(reflection.name)];
if (reflection.signatures?.length) {
md.push('()');
}
if (typeParams && reflection.typeParameters) {
const typeParameters = reflection.typeParameters
.map((typeParameter) => typeParameter.name)
.join(', ');
md.push(`${backTicks(`<${typeParameters}>`)}`);
}
return md.join('');
}
7 changes: 2 additions & 5 deletions packages/typedoc-plugin-markdown/src/partials/member.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,7 @@ import {
ReflectionKind,
} from 'typedoc';
import { heading } from '../support/els';
import {
getReflectionHeadingLevel,
getReflectionTitle,
} from '../support/helpers';
import { getReflectionHeadingLevel } from '../support/helpers';
import { MarkdownThemeRenderContext } from '../theme-render-context';

export function member(
Expand All @@ -26,7 +23,7 @@ export function member(
}

if (!reflection.hasOwnDocument) {
md.push(heading(headingLevel, `${getReflectionTitle(reflection)}`));
md.push(heading(headingLevel, context.partials.memberTitle(reflection)));
}

if (
Expand Down
6 changes: 4 additions & 2 deletions packages/typedoc-plugin-markdown/src/partials/page.title.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { DeclarationReflection, PageEvent, ProjectReflection } from 'typedoc';
import { getProjectDisplayName, getReflectionTitle } from '../support/helpers';
import { getProjectDisplayName } from '../support/helpers';
import { MarkdownThemeRenderContext } from '../theme-render-context';

export function pageTitle(
Expand All @@ -16,7 +16,9 @@ export function pageTitle(
),
);
} else {
md.push(getReflectionTitle(page.model as DeclarationReflection, true));
md.push(
context.partials.memberTitle(page.model as DeclarationReflection, true),
);
}
return md.join(' ');
}
3 changes: 3 additions & 0 deletions packages/typedoc-plugin-markdown/src/resources.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ import { reflectionMember } from './partials/member.reflection';
import { signatureMemberIdentifier } from './partials/member.signature.identifier';
import { signatureMember } from './partials/member.signature';
import { sources } from './partials/member.sources';
import { memberTitle } from './partials/member.title';
import { member } from './partials/member';
import { members } from './partials/members';
import { navigation } from './partials/navigation';
Expand Down Expand Up @@ -100,6 +101,7 @@ export type Partials = {
signatureMemberIdentifier: (signature: SignatureReflection) => string;
signatureMember: (signature: SignatureReflection, parentHeadingLevel?: number | undefined) => string;
sources: (reflection: DeclarationReflection | SignatureReflection) => string;
memberTitle: (reflection: DeclarationReflection, typeParams?: boolean) => string;
member: (reflection: DeclarationReflection, parentHeadingLevel?: number | undefined) => string;
members: (container: ContainerReflection) => string;
navigation: (project: ProjectReflection) => string;
Expand Down Expand Up @@ -151,6 +153,7 @@ export const partials = (context: MarkdownThemeRenderContext): Partials => ({
signatureMemberIdentifier: bind(signatureMemberIdentifier, context),
signatureMember: bind(signatureMember, context),
sources: bind(sources, context),
memberTitle: bind(memberTitle, context),
member: bind(member, context),
members: bind(members, context),
navigation: bind(navigation, context),
Expand Down
16 changes: 1 addition & 15 deletions packages/typedoc-plugin-markdown/src/support/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {
SignatureReflection,
} from 'typedoc';
import { backTicks } from './els';
import { escapeChars, stripLineBreaks } from './utils';
import { stripLineBreaks } from './utils';

export function getIndexHeadingLevel(
reflection: DeclarationReflection | ProjectReflection,
Expand Down Expand Up @@ -55,20 +55,6 @@ export function getReflectionHeadingLevel(
return reflection.parent?.hasOwnDocument ? 2 : 4;
}

export function getReflectionTitle(
reflection: DeclarationReflection,
typeParams = false,
) {
const md = [escapeChars(reflection.name)];
if (reflection.signatures?.length) {
md.push('()');
}
if (typeParams) {
md.push(getTypeParameters(reflection));
}
return md.join('');
}

export function getTypeParameters(reflection: DeclarationReflection) {
if (reflection.typeParameters) {
const typeParameters = reflection.typeParameters
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`Breadcrumbs: (with readme) should compile README breadcrumbs' 1`] = `"**typedoc-plugin-markdown**"`;

exports[`Breadcrumbs: (with readme) should compile class breadcrumbs' 1`] = `"[typedoc-plugin-markdown](modules.md) > Breadcrumbs"`;

exports[`Breadcrumbs: (with readme) should compile entryPoint (globals) breadcrumbs' 1`] = `"[typedoc-plugin-markdown](modules.md) > typedoc-plugin-markdown"`;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
exports[`Generics: should compile class with type params 1`] = `
"[partial: breadcrumbs]
# ClassWithTypeParams\\<T, V\\>
# ClassWithTypeParams\`<T, V>\`
**\`Class\`**
Expand Down
10 changes: 0 additions & 10 deletions packages/typedoc-plugin-markdown/test/specs/breadcrumbs.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,6 @@ describe(`Breadcrumbs:`, () => {
context.activeLocation = 'breadcrumbs.md';
});

test(`should compile README breadcrumbs'`, () => {
expect(
context.partials.breadcrumbs({
project: project,
model: project,
url: 'README.md',
} as any),
).toMatchSnapshot();
});

test(`should compile entryPoint (globals) breadcrumbs'`, () => {
expect(
context.partials.breadcrumbs({
Expand Down

0 comments on commit db5ebc3

Please sign in to comment.