Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .changeset/typedoc-multi-example-double-comma.md

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we can do an empty changeset? Since this does not change the backend at all 👍🏼

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good pt! All done @wobsoriano

Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
---
---
27 changes: 27 additions & 0 deletions .typedoc/__tests__/catch-all-replacements.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import { describe, expect, it } from 'vitest';

// @ts-expect-error — .mjs plugin has no type declarations
import { applyCatchAllMdReplacements } from '../custom-plugin.mjs';

/**
* Unit coverage for the `getCatchAllReplacements()` rules exercised through the
* exported `applyCatchAllMdReplacements()` entry point.
*/
describe('applyCatchAllMdReplacements', () => {
it('renders a single `@example` as "Example: `value`."', () => {
expect(applyCatchAllMdReplacements('**Example** `foo`')).toBe('Example: `foo`.');
});

it('joins multiple `@example` blocks with ", "', () => {
expect(applyCatchAllMdReplacements('**Examples** `a` `b` `c`')).toBe('Examples: `a`, `b`, `c`.');
});

it('does not corrupt examples that contain internal spaces', () => {
// Regression: splitting the captured group on ' ' rejoined each example's
// internal spaces with ", ", producing a spurious `,,` inside array literals.
const input = '**Examples** `["/orgs/:slug", "/orgs/:slug/(.*)"]` `["/orgs/:id", "/orgs/:id/(.*)"]`';
expect(applyCatchAllMdReplacements(input)).toBe(
'Examples: `["/orgs/:slug", "/orgs/:slug/(.*)"]`, `["/orgs/:id", "/orgs/:id/(.*)"]`.',
);
});
});
4 changes: 3 additions & 1 deletion .typedoc/custom-plugin.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -395,7 +395,9 @@ function getCatchAllReplacements() {
*/
pattern: /\*\*Examples\*\* ((?:`[^`]+`)(?: `[^`]+`)*)/g,
replace: (/** @type {string} */ _match, /** @type {string} */ capturedGroup) => {
return `Examples: ${capturedGroup.split(' ').join(', ')}.`;
// Match backtick-delimited examples individually; splitting on ' ' breaks examples with internal spaces.
const examples = capturedGroup.match(/`[^`]+`/g) ?? [];
return `Examples: ${examples.join(', ')}.`;
},
},
];
Expand Down
Loading