-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
docs: render multiple @example blocks as tabbed code groups #3817
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 5 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
bf68cec
docs: render multiple @example blocks as tabbed code groups
Shinigami92 ab237bc
test(apidocs): add multi-@example fixtures for tabbed code groups
Shinigami92 d0114ad
docs: require title comment in multi-@example tabs
Shinigami92 383747a
docs: strip title comment from code-group tab body
Shinigami92 abdf90b
test: use snapshot for codeGroupToHtml rendering
Shinigami92 4757acd
refactor: simplify extractCodeGroupTitle
Shinigami92 125eef4
refactor: include full example in code-group title error
Shinigami92 6b88dcc
fix(docs): refresh examples across all code-group tabs
Shinigami92 72a37a4
refactor(docs): drop redundant codeBlock computed
Shinigami92 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -109,5 +109,6 @@ yarn.lock | |
|
|
||
| cypress/screenshots | ||
| cypress/videos | ||
| .playwright-mcp/ | ||
|
|
||
| _local/ | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| // Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html | ||
|
|
||
| exports[`markdown > codeGroupToHtml() > renders a plain code block for a single example 1`] = ` | ||
| "<div class="language-ts"><button title="Copy Code" class="copy"></button><span class="lang">ts</span><pre class="shiki shiki-themes github-light github-dark" style="--shiki-light:#24292e;--shiki-dark:#e1e4e8;--shiki-light-bg:#fff;--shiki-dark-bg:#24292e" tabindex="0" dir="ltr" v-pre><code><span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583">const</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF"> a</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583"> =</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF"> 1</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8">;</span></span></code></pre> | ||
| </div>" | ||
| `; | ||
|
|
||
| exports[`markdown > codeGroupToHtml() > renders a tabbed code group with titles from leading comments 1`] = ` | ||
| "<div class="vp-code-group"><div class="tabs"><input type="radio" name="group-0" id="tab-1" checked /><label data-title="First title" for="tab-1">First title</label><input type="radio" name="group-0" id="tab-2" /><label data-title="Second title" for="tab-2">Second title</label></div><div class="blocks"> | ||
| <div class="language-ts active"><button title="Copy Code" class="copy"></button><span class="lang">ts</span><pre class="shiki shiki-themes github-light github-dark" style="--shiki-light:#24292e;--shiki-dark:#e1e4e8;--shiki-light-bg:#fff;--shiki-dark-bg:#24292e" tabindex="0" dir="ltr" v-pre><code><span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583">const</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF"> a</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583"> =</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF"> 1</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8">;</span></span></code></pre> | ||
| </div><div class="language-ts"><button title="Copy Code" class="copy"></button><span class="lang">ts</span><pre class="shiki shiki-themes github-light github-dark" style="--shiki-light:#24292e;--shiki-dark:#e1e4e8;--shiki-light-bg:#fff;--shiki-dark-bg:#24292e" tabindex="0" dir="ltr" v-pre><code><span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583">const</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF"> b</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583"> =</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF"> 2</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8">;</span></span></code></pre> | ||
| </div></div></div> | ||
| " | ||
| `; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,36 @@ | ||
| import { beforeAll, describe, expect, it } from 'vitest'; | ||
| import { | ||
| codeGroupToHtml, | ||
| initMarkdownRenderer, | ||
| } from '../../../scripts/shared/markdown'; | ||
|
|
||
| describe('markdown', () => { | ||
| beforeAll(async () => { | ||
| await initMarkdownRenderer(); | ||
| }); | ||
|
|
||
| describe('codeGroupToHtml()', () => { | ||
| it('renders a plain code block for a single example', async () => { | ||
| const html = await codeGroupToHtml(['const a = 1;']); | ||
|
|
||
| expect(html).toMatchSnapshot(); | ||
| }); | ||
|
|
||
| it('renders a tabbed code group with titles from leading comments', async () => { | ||
| const html = await codeGroupToHtml([ | ||
| '// First title\nconst a = 1;', | ||
| '// Second title\nconst b = 2;', | ||
| ]); | ||
|
|
||
| expect(html).toMatchSnapshot(); | ||
| }); | ||
|
|
||
| it('throws when a multi-example block is missing a title comment', async () => { | ||
| await expect( | ||
| codeGroupToHtml(['// First title\nconst a = 1;', 'const b = 2;']) | ||
| ).rejects.toThrow( | ||
| /Example 2 in a multi-example block must start with a `\/\/ Title` line comment/ | ||
| ); | ||
| }); | ||
| }); | ||
| }); |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.