Skip to content

Commit

Permalink
feat: Expose preserveAnchorCasing option (#301)
Browse files Browse the repository at this point in the history
  • Loading branch information
tgreyuk committed Apr 9, 2022
1 parent 787748f commit f51ff45
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 4 deletions.
7 changes: 4 additions & 3 deletions packages/typedoc-plugin-markdown/README.md
Expand Up @@ -5,7 +5,6 @@ A plugin for [TypeDoc](https://github.com/TypeStrong/typedoc) that renders TypeS
[![npm](https://img.shields.io/npm/v/typedoc-plugin-markdown.svg)](https://www.npmjs.com/package/typedoc-plugin-markdown)
[![Build Status](https://github.com/tgreyuk/typedoc-plugin-markdown/actions/workflows/ci.yml/badge.svg?branch=master)](https://github.com/tgreyuk/typedoc-plugin-markdown/actions/workflows/ci.yml)


## What it does?

The plugin replaces the default HTML theme with a built-in Markdown theme and exposes some additional options.
Expand Down Expand Up @@ -38,13 +37,15 @@ The following options can be used in addition to relevant [TypeDoc options](http
- `--hideBreadcrumbs<boolean>`<br>
Do not render breadcrumbs in template header. Defaults to `false`.
- `--hideInPageTOC<boolean>`<br>
Do not render in-page table of contents items. Defaults to `false`.
Do not render in-page table of contents items. Defaults to `false`.
- `--hideMembersSymbol<boolean>`<br>
Do not add special symbols for class members. Defaults to `false`.
Do not add special symbols for class members. Defaults to `false`.
- `--publicPath<string>`<br>
Specify the base path for all urls. If undefined urls will be relative. Defaults to `.`.
- `--namedAnchors<boolean>`<br>
Use HTML named anchors tags for implementations that do not assign header ids. Defaults to `false`.
- `--preserveAnchorCasing<boolean>`<br>
Preserve anchor id casing for implementations where original case is desirable. Defaults to `false`.

## License

Expand Down
7 changes: 7 additions & 0 deletions packages/typedoc-plugin-markdown/src/index.ts
Expand Up @@ -73,6 +73,13 @@ export function load(app: Application) {
type: ParameterType.Boolean,
defaultValue: false,
});

app.options.addDeclaration({
help: '[Markdown Plugin] Preserve anchor casing when generating links.',
name: 'preserveAnchorCasing',
type: ParameterType.Boolean,
defaultValue: false,
});
}

export { MarkdownTheme };
8 changes: 7 additions & 1 deletion packages/typedoc-plugin-markdown/src/theme.ts
Expand Up @@ -38,6 +38,7 @@ export class MarkdownTheme extends Theme {
readme!: string;
out!: string;
publicPath!: string;
preserveAnchorCasing!: boolean;

project?: ProjectReflection;
reflection?: DeclarationReflection;
Expand Down Expand Up @@ -65,6 +66,9 @@ export class MarkdownTheme extends Theme {
this.readme = this.getOption('readme') as string;
this.out = this.getOption('out') as string;
this.publicPath = this.getOption('publicPath') as string;
this.preserveAnchorCasing = this.getOption(
'preserveAnchorCasing',
) as boolean;

this.listenTo(this.owner, {
[RendererEvent.BEGIN]: this.onBeginRenderer,
Expand Down Expand Up @@ -164,7 +168,9 @@ export class MarkdownTheme extends Theme {
container.url &&
(!reflection.url || !MarkdownTheme.URL_PREFIX.test(reflection.url))
) {
const reflectionId = reflection.name.toLowerCase();
const reflectionId = this.preserveAnchorCasing
? reflection.name
: reflection.name.toLowerCase();

this.anchorMap[container.url]
? this.anchorMap[container.url].push(reflectionId)
Expand Down

0 comments on commit f51ff45

Please sign in to comment.