Skip to content

Commit

Permalink
fix: Handle non-unique anchor ids (update) (#303)
Browse files Browse the repository at this point in the history
  • Loading branch information
tgreyuk committed Apr 21, 2022
1 parent f5a8291 commit 2deb7b7
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 8 deletions.
18 changes: 12 additions & 6 deletions packages/typedoc-plugin-markdown/src/theme.ts
Expand Up @@ -139,7 +139,7 @@ export class MarkdownTheme extends Theme {
}
}
} else if (reflection.parent) {
this.applyAnchorUrl(reflection, reflection.parent);
this.applyAnchorUrl(reflection, reflection.parent, true);
}
return urls;
}
Expand All @@ -163,7 +163,11 @@ export class MarkdownTheme extends Theme {
return url.replace(/^_/, '');
}

applyAnchorUrl(reflection: Reflection, container: Reflection) {
applyAnchorUrl(
reflection: Reflection,
container: Reflection,
isSymbol = false,
) {
if (
container.url &&
(!reflection.url || !MarkdownTheme.URL_PREFIX.test(reflection.url))
Expand All @@ -172,11 +176,13 @@ export class MarkdownTheme extends Theme {
? reflection.name
: reflection.name.toLowerCase();

this.anchorMap[container.url]
? this.anchorMap[container.url].push(reflectionId)
: (this.anchorMap[container.url] = [reflectionId]);
if (isSymbol) {
this.anchorMap[container.url]
? this.anchorMap[container.url].push(reflectionId)
: (this.anchorMap[container.url] = [reflectionId]);
}

const count = this.anchorMap[container.url].filter(
const count = this.anchorMap[container.url]?.filter(
(id) => id === reflectionId,
)?.length;

Expand Down
Expand Up @@ -22,10 +22,12 @@ exports[`TOC: (default) should display toc for module' 1`] = `
### Type aliases
- [answer](../modules.md#answer)
- [Answer](../modules.md#answer)
- [answer](../modules.md#answer-1)
### Variables
- [answer](../modules.md#answer-1)
- [\\\\_answer](../modules.md#_answer)
- [answer](../modules.md#answer-2)
"
`;
7 changes: 7 additions & 0 deletions packages/typedoc-plugin-markdown/test/stubs/src/toc.ts
@@ -1,7 +1,14 @@
export const _answer = {
Answer: 'yes',
answer: 'no',
};

export type answer = 'yes' | 'no';

export const answer = 'yes';

export type Answer = 'yes' | 'no';

export class SomeClass {
someMethod() {
return true;
Expand Down

0 comments on commit 2deb7b7

Please sign in to comment.