Skip to content

Commit

Permalink
feat: Added 'titleTemplate' option
Browse files Browse the repository at this point in the history
  • Loading branch information
tgreyuk committed Jul 24, 2023
1 parent 5a85354 commit d5af818
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 12 deletions.
20 changes: 14 additions & 6 deletions packages/typedoc-plugin-markdown/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,18 +81,26 @@ export function load(app: Application) {
defaultValue: false,
});


app.options.addDeclaration({
help: '[Markdown Plugin] Specify the Type Declaration Render Style',
name: 'objectLiteralTypeDeclarationStyle',
type: ParameterType.String,
defaultValue: "table",
defaultValue: 'table',
validate: (x) => {
const availableValues = ["table", "list"];
if (!availableValues.includes(x)){
throw new Error(`Wrong value for objectLiteralTypeDeclarationStyle, the expected value is one of ${availableValues}`)
const availableValues = ['table', 'list'];
if (!availableValues.includes(x)) {
throw new Error(
`Wrong value for objectLiteralTypeDeclarationStyle, the expected value is one of ${availableValues}`,
);
}
}
},
});

app.options.addDeclaration({
help: '[Markdown Plugin] Specify a template for displaying page titles.',
name: 'titleTemplate',
type: ParameterType.String,
defaultValue: '{kind}: {title}',
});
}
export { MarkdownTheme };
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,11 @@ export default function (theme: MarkdownTheme) {
Handlebars.registerHelper(
'reflectionTitle',
function (this: PageEvent<any>, shouldEscape = true) {
const title: string[] = [''];
if (this.model?.kind && this.url !== this.project.url) {
title.push(`${ReflectionKind.singularString(this.model.kind)}: `);
}
const titleTemplate = theme.getOption('titleTemplate') as string;
if (this.url === this.project.url) {
title.push(theme.indexTitle || getDisplayName(this.model));
return theme.indexTitle || getDisplayName(this.model);
} else {
const title: string[] = [''];
title.push(
shouldEscape ? escapeChars(this.model.name) : this.model.name,
);
Expand All @@ -23,8 +21,12 @@ export default function (theme: MarkdownTheme) {
.join(', ');
title.push(`<${typeParameters}${shouldEscape ? '\\>' : '>'}`);
}
return this.model.kind
? titleTemplate
.replace('{title}', title.join(''))
.replace('{kind}', ReflectionKind.singularString(this.model.kind))
: title.join('');
}
return title.join('');
},
);
}

0 comments on commit d5af818

Please sign in to comment.