Skip to content

Commit d75be61

Browse files
authored
chore(repo): Typedoc: Handle <code> injection in function signatures (#7010)
1 parent 3e0ef92 commit d75be61

File tree

3 files changed

+54
-13
lines changed

3 files changed

+54
-13
lines changed

.changeset/silly-jars-shave.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
---
2+
---

.typedoc/custom-theme.mjs

Lines changed: 51 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,8 @@ class ClerkMarkdownThemeContext extends MarkdownThemeContext {
4444

4545
const superPartials = this.partials;
4646

47+
this._insideFunctionSignature = false;
48+
4749
this.partials = {
4850
...superPartials,
4951
/**
@@ -153,10 +155,17 @@ class ClerkMarkdownThemeContext extends MarkdownThemeContext {
153155
);
154156
}
155157

158+
const prevInsideParams = this._insideFunctionSignature;
159+
this._insideFunctionSignature = true;
156160
md.push(this.partials.signatureParameters(model.parameters || []));
161+
this._insideFunctionSignature = prevInsideParams;
157162

158163
if (model.type) {
159-
md.push(`: ${this.partials.someType(model.type)}`);
164+
const prevInsideType = this._insideFunctionSignature;
165+
this._insideFunctionSignature = true;
166+
const typeOutput = this.partials.someType(model.type);
167+
this._insideFunctionSignature = prevInsideType;
168+
md.push(`: ${typeOutput}`);
160169
}
161170

162171
const result = md.join('');
@@ -353,6 +362,11 @@ class ClerkMarkdownThemeContext extends MarkdownThemeContext {
353362
.replace(/<code>/g, '')
354363
.replace(/<\/code>/g, '');
355364

365+
// Only wrap in <code> if NOT inside a function signature
366+
if (this._insideFunctionSignature) {
367+
return output;
368+
}
369+
356370
return `<code>${output}</code>`;
357371
},
358372
/**
@@ -371,6 +385,11 @@ class ClerkMarkdownThemeContext extends MarkdownThemeContext {
371385
.replace(/<code>/g, '')
372386
.replace(/<\/code>/g, '');
373387

388+
// Only wrap in <code> if NOT inside a function signature
389+
if (this._insideFunctionSignature) {
390+
return output;
391+
}
392+
374393
return `<code>${output}</code>`;
375394
},
376395
/**
@@ -394,6 +413,11 @@ class ClerkMarkdownThemeContext extends MarkdownThemeContext {
394413
)
395414
.join(delimiter);
396415

416+
// Only wrap in <code> if NOT inside a function signature
417+
if (this._insideFunctionSignature) {
418+
return output;
419+
}
420+
397421
return `<code>${output}</code>`;
398422
},
399423
/**
@@ -492,6 +516,32 @@ ${tabs}
492516
.replace(/<code>/g, '')
493517
.replace(/<\/code>/g, '');
494518

519+
// Only wrap in <code> if NOT inside a function signature
520+
if (this._insideFunctionSignature) {
521+
return output;
522+
}
523+
524+
return `<code>${output}</code>`;
525+
},
526+
/**
527+
* Ensures that reflection types (like Simplify wrapped types) are wrapped in a single codeblock
528+
* @param {import('typedoc').ReflectionType} model
529+
*/
530+
reflectionType: model => {
531+
const defaultOutput = superPartials.reflectionType(model);
532+
533+
const output = defaultOutput
534+
// Remove any backticks
535+
.replace(/`/g, '')
536+
// Remove any `<code>` and `</code>` tags
537+
.replace(/<code>/g, '')
538+
.replace(/<\/code>/g, '');
539+
540+
// Only wrap in <code> if NOT inside a function signature
541+
if (this._insideFunctionSignature) {
542+
return output;
543+
}
544+
495545
return `<code>${output}</code>`;
496546
},
497547
/**

packages/backend/src/tokens/verify.ts

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -40,22 +40,11 @@ export type VerifyTokenOptions = Simplify<
4040
* Verifies a Clerk-generated token signature. Networkless if the `jwtKey` is provided. Otherwise, performs a network call to retrieve the JWKS from the [Backend API](https://clerk.com/docs/reference/backend-api/tag/JWKS#operation/GetJWKS){{ target: '_blank' }}.
4141
*
4242
* @param token - The token to verify.
43-
* @param options - Options for verifying the token.
43+
* @param options - Options for verifying the token. It is recommended to set these options as [environment variables](/docs/guides/development/clerk-environment-variables#api-and-sdk-configuration) where possible, and then pass them to the function. For example, you can set the `secretKey` option using the `CLERK_SECRET_KEY` environment variable, and then pass it to the function like this: `verifyToken(token, { secretKey: process.env.CLERK_SECRET_KEY })`.
4444
*
4545
* @displayFunctionSignature
4646
* @hideReturns
4747
*
48-
* @paramExtension
49-
*
50-
* ### `VerifyTokenOptions`
51-
*
52-
* It is recommended to set these options as [environment variables](/docs/guides/development/clerk-environment-variables#api-and-sdk-configuration) where possible, and then pass them to the function. For example, you can set the `secretKey` option using the `CLERK_SECRET_KEY` environment variable, and then pass it to the function like this: `createClerkClient({ secretKey: process.env.CLERK_SECRET_KEY })`.
53-
*
54-
* > [!WARNING]
55-
* You must provide either `jwtKey` or `secretKey`.
56-
*
57-
* <Typedoc src="backend/verify-token-options" />
58-
*
5948
* @example
6049
*
6150
* The following example demonstrates how to use the [JavaScript Backend SDK](https://clerk.com/docs/reference/backend/overview) to verify the token signature.

0 commit comments

Comments
 (0)