Skip to content

Commit

Permalink
fix(core): fix anchor links containing generics (#655)
Browse files Browse the repository at this point in the history
  • Loading branch information
tgreyuk committed Jul 19, 2024
1 parent 25769b9 commit f461ada
Show file tree
Hide file tree
Showing 8 changed files with 36 additions and 3 deletions.
5 changes: 5 additions & 0 deletions .changeset/many-oranges-agree.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'typedoc-plugin-markdown': patch
---

- Fix anchor links containing generics (#655)
2 changes: 1 addition & 1 deletion devtools/packages/fixtures/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ function writeMarkdown(
'-options',
path.join(__dirname, 'typedoc.cjs'),
'-logLevel',
'Warn',
'None',
'-out',
fullPath,
],
Expand Down
6 changes: 5 additions & 1 deletion devtools/packages/testing/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ export function expectFileToEqual(
outputFileStrategy: 'modules' | 'members' | ('modules' | 'members')[],
file: string | string[],
limit?: number,
range?: Array<number>,
) {
const outputFileStrategies = Array.isArray(outputFileStrategy)
? outputFileStrategy
Expand All @@ -23,7 +24,10 @@ export function expectFileToEqual(
optionDir,
isArray ? file[index] : file,
);
const actual = fs.readFileSync(fullPath).toString();
let actual = fs.readFileSync(fullPath).toString();
if (range) {
actual = actual.split('\n').slice(range[0], range[1]).join('\n');
}
expect(actual).toMatchSnapshot(
`(Output File Strategy "${outputFileStrategy}") (Option Group "${
index + 1
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -582,7 +582,7 @@ export class UrlBuilder {
anchorParts.push(
reflection.typeParameters
.map((typeParameter) => typeParameter.name)
.join(''),
.join('-'),
);
}
return anchorParts.join('');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
* - {@link SameName.prop}
* - {@link prop:var}
* - {@link _prop_with_underscore:var}
* - {@link TypeWithGenerics}
*
* External links:
*
Expand Down Expand Up @@ -97,6 +98,8 @@ export enum CommentEnum {
MemberB,
}

export type TypeWithGenerics<C, D> = C | D;

export interface SameName {
prop: string;
propb: string;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,18 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`Comments should compile @links with anchors: (Output File Strategy "modules") (Option Group "1") 1`] = `
"- [CommentInterface](README.md#commentinterface) - Links to CommentInterface
- [Links to CommentInterface.prop](README.md#prop)
- [Links to CommentInterface.propb](README.md#propb-1)
- [CommentEnum.MemberB](README.md#commentenum)
- [SameName:var](README.md#samename-1)
- [SameName:interface](README.md#samename)
- [SameName.prop](README.md#prop-2)
- [prop:var](README.md#prop-3)
- [_prop_with_underscore:var](README.md#_prop_with_underscore)
- [TypeWithGenerics](README.md#typewithgenericsc-d)"
`;

exports[`Comments should compile comments for module: (Output File Strategy "members") (Option Group "1") 1`] = `
"# typedoc-stubs
Expand All @@ -18,6 +31,7 @@ Links using \`{@link}\` inline tags.
- [SameName.prop](interfaces/SameName.md#prop)
- [prop:var](variables/prop.md)
- [_prop_with_underscore:var](variables/prop_with_underscore.md)
- [TypeWithGenerics](type-aliases/TypeWithGenerics.md)
External links:
Expand Down Expand Up @@ -92,6 +106,7 @@ Some <p> html </p> inside codeblock
## Type Aliases
- [TypeDeclarationTable](type-aliases/TypeDeclarationTable.md)
- [TypeWithGenerics](type-aliases/TypeWithGenerics.md)
- [typeWithBlockTags](type-aliases/typeWithBlockTags.md)
## Variables
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -975,6 +975,7 @@ exports[`Urls should gets Urls with media assets: outputFileStrategy: members 1`
"interfaces/InterfacePropertiesTable.md",
"interfaces/SameName.md",
"type-aliases/TypeDeclarationTable.md",
"type-aliases/TypeWithGenerics.md",
"type-aliases/typeWithBlockTags.md",
"variables/SameName.md",
"variables/TypeDeclarationTable.md",
Expand All @@ -1001,6 +1002,7 @@ exports[`Urls should gets Urls with media assets: outputFileStrategy: members 2`
"Interface.SameName.md",
"README.md",
"TypeAlias.TypeDeclarationTable.md",
"TypeAlias.TypeWithGenerics.md",
"TypeAlias.typeWithBlockTags.md",
"Variable.SameName.md",
"Variable.TypeDeclarationTable.md",
Expand Down
4 changes: 4 additions & 0 deletions packages/typedoc-plugin-markdown/test/specs/comments.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ describe(`Comments`, () => {
expectFileToEqual('comments', ['members'], ['README.md']);
});

test(`should compile @links with anchors`, () => {
expectFileToEqual('comments', ['modules'], ['README.md'], 1, [8, 18]);
});

test(`should handle single example tags`, () => {
expectFileToEqual(
'comments',
Expand Down

0 comments on commit f461ada

Please sign in to comment.