Skip to content

Commit b468c4a

Browse files
committed
Add tabbed content support in documentation and implement conversion to Docusaurus Tabs components
- Introduced a new section in README.md detailing how to create tabbed content using HTML comment markers for Docusaurus. - Implemented a function in repo-transforms.js to convert GitHub-style tab markers into Docusaurus Tabs components, enhancing documentation interactivity. Signed-off-by: Pete Cheslock <[email protected]>
1 parent b01a8a0 commit b468c4a

File tree

2 files changed

+92
-1
lines changed

2 files changed

+92
-1
lines changed

README.md

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,43 @@ To add other remote content (non-component):
161161
**For local website content:**
162162
- Follow the standard pull request process below
163163

164+
### Creating Tabs in Remote Content
165+
166+
When writing documentation in source repositories (like llm-d/llm-d) that will be synced to this Docusaurus site, you can create tabbed content using HTML comment markers. These are invisible in GitHub but will be transformed into Docusaurus tabs during the build.
167+
168+
**In your GitHub README:**
169+
```markdown
170+
### Deploy Model Servers
171+
172+
<!-- TABS:START -->
173+
<!-- TAB:GKE (H200):default -->
174+
```bash
175+
kubectl apply -k ./manifests/modelserver/gke -n ${NAMESPACE}
176+
```
177+
178+
<!-- TAB:GKE (B200) -->
179+
```bash
180+
kubectl apply -k ./manifests/modelserver/gke-a4 -n ${NAMESPACE}
181+
```
182+
183+
<!-- TAB:CoreWeave -->
184+
```bash
185+
kubectl apply -k ./manifests/modelserver/coreweave -n ${NAMESPACE}
186+
```
187+
<!-- TABS:END -->
188+
```
189+
190+
**Key points:**
191+
- Use `<!-- TABS:START -->` and `<!-- TABS:END -->` to wrap the entire tabbed section
192+
- Use `<!-- TAB:Label -->` before each tab's content
193+
- Add `:default` after the label to make it the default selected tab (e.g., `<!-- TAB:GKE:default -->`)
194+
- **No imports needed** - the transformation automatically adds them
195+
- On GitHub, the HTML comments are invisible, showing clean markdown
196+
- On Docusaurus, these are transformed into proper `<Tabs>` components
197+
198+
**Result on Docusaurus:**
199+
The content will automatically be transformed with the proper Tabs imports and components, creating an interactive tabbed interface.
200+
164201
### Troubleshooting
165202
166203
| Problem | Solution |
@@ -170,6 +207,7 @@ To add other remote content (non-component):
170207
| Links broken | Make sure you're using `createStandardTransform()` |
171208
| Component not showing | Check `components-data.yaml` and repository accessibility |
172209
| Wrong sidebar order | Adjust `sidebarPosition` numbers in configuration |
210+
| Tabs not rendering | Check that you have both `TABS:START` and `TABS:END` markers |
173211
174212
## BEFORE DOING A PULL REQUEST
175213

remote-content/remote-sources/repo-transforms.js

Lines changed: 54 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,12 +55,65 @@ function getInternalGuidePath(githubUrl) {
5555
return null;
5656
}
5757

58+
/**
59+
* Convert GitHub-friendly tab markers to Docusaurus Tabs components
60+
*/
61+
function convertTabsToDocusaurus(content) {
62+
// Check if there are any tab blocks
63+
const hasTabBlocks = /<!-- TABS:START -->/.test(content);
64+
if (!hasTabBlocks) return content;
65+
66+
// Pattern to match tab blocks
67+
const tabBlockRegex = /<!-- TABS:START -->\n([\s\S]*?)<!-- TABS:END -->/g;
68+
69+
const transformedContent = content.replace(tabBlockRegex, (match, tabsContent) => {
70+
// Extract individual tabs
71+
const tabRegex = /<!-- TAB:([^:]+)(?::default)? -->\n([\s\S]*?)(?=<!-- TAB:|<!-- TABS:END)/g;
72+
const tabs = [];
73+
let tabMatch;
74+
75+
while ((tabMatch = tabRegex.exec(tabsContent)) !== null) {
76+
const label = tabMatch[1].trim();
77+
const content = tabMatch[2].trim();
78+
const isDefault = match.includes(`<!-- TAB:${label}:default -->`);
79+
tabs.push({ label, content, isDefault });
80+
}
81+
82+
if (tabs.length === 0) return match;
83+
84+
// Generate Docusaurus Tabs component (without imports here)
85+
let result = `<Tabs>\n`;
86+
87+
tabs.forEach(tab => {
88+
const defaultAttr = tab.isDefault ? ' default' : '';
89+
result += ` <TabItem value="${tab.label.toLowerCase().replace(/[^a-z0-9]/g, '-')}" label="${tab.label}"${defaultAttr}>\n\n`;
90+
result += `${tab.content}\n\n`;
91+
result += ` </TabItem>\n`;
92+
});
93+
94+
result += `</Tabs>`;
95+
96+
return result;
97+
});
98+
99+
// Add imports at the top of the file if tabs were found
100+
if (transformedContent !== content) {
101+
return `import Tabs from '@theme/Tabs';\nimport TabItem from '@theme/TabItem';\n\n${transformedContent}`;
102+
}
103+
104+
return transformedContent;
105+
}
106+
58107
/**
59108
* Apply essential MDX compatibility fixes and content transformations
60109
* Combines all content-only transformations that don't require repository information
61110
*/
62111
function applyBasicMdxFixes(content) {
63-
return content
112+
// First convert tabs to Docusaurus format
113+
let transformed = convertTabsToDocusaurus(content);
114+
115+
// Then apply other MDX fixes
116+
return transformed
64117
// Convert GitHub-style callouts to Docusaurus admonitions
65118
.replace(/^> \[!(NOTE|TIP|IMPORTANT|WARNING|CAUTION)\]\s*\n((?:> .*\n?)*)/gm, (match, type, content) => {
66119
// Map GitHub callout types to Docusaurus admonition types

0 commit comments

Comments
 (0)