forked from fern-api/fern-platform
-
Notifications
You must be signed in to change notification settings - Fork 0
feat: expand MDX components in markdown routes #1
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
Draft
devin-ai-integration
wants to merge
2
commits into
app
Choose a base branch
from
devin/1750696722-expand-mdx-components
base: app
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
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
186 changes: 186 additions & 0 deletions
186
packages/fern-docs/bundle/src/server/llm-txt-md.test.ts
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,186 @@ | ||
| import { convertToLlmTxtMarkdown } from "./llm-txt-md"; | ||
|
|
||
| describe("llm-txt-md", () => { | ||
| describe("convertToLlmTxtMarkdown", () => { | ||
| it("should handle regular markdown without MDX components", () => { | ||
| const markdown = "# Test\n\nThis is regular markdown."; | ||
| const result = convertToLlmTxtMarkdown(markdown, "Test Page", "md"); | ||
|
|
||
| expect(result).toContain("# Test Page"); | ||
| expect(result).toContain("This is regular markdown."); | ||
| }); | ||
|
|
||
| it("should expand TSFetchCodeBlock components to code blocks", () => { | ||
| const markdown = `# Test | ||
|
|
||
| <TSFetchCodeBlock> | ||
| console.log("Hello, world!"); | ||
| </TSFetchCodeBlock>`; | ||
|
|
||
| const result = convertToLlmTxtMarkdown(markdown, "Test Page", "mdx"); | ||
|
|
||
| expect(result).toContain("# Test Page"); | ||
| expect(result).toContain("```typescript"); | ||
| expect(result).toContain('console.log("Hello, world!");'); | ||
| expect(result).not.toContain("<TSFetchCodeBlock>"); | ||
| }); | ||
|
|
||
| it("should expand CodeGroup components to multiple code blocks", () => { | ||
| const markdown = `# Test | ||
|
|
||
| <CodeGroup> | ||
| <Code language="javascript"> | ||
| console.log("JS code"); | ||
| </Code> | ||
| <Code language="python"> | ||
| print("Python code") | ||
| </Code> | ||
| </CodeGroup>`; | ||
|
|
||
| const result = convertToLlmTxtMarkdown(markdown, "Test Page", "mdx"); | ||
|
|
||
| expect(result).toContain("# Test Page"); | ||
| expect(result).toContain("```javascript"); | ||
| expect(result).toContain('console.log("JS code");'); | ||
| expect(result).toContain("```python"); | ||
| expect(result).toContain('print("Python code")'); | ||
| expect(result).not.toContain("<CodeGroup>"); | ||
| expect(result).not.toContain("<Code"); | ||
| }); | ||
|
|
||
| it("should expand Template components with variable replacement", () => { | ||
| const markdown = `# Test | ||
|
|
||
| <Template data={{"API_KEY": "test-key-123", "BASE_URL": "https://api.example.com"}}> | ||
| Use your API key: {{API_KEY}} | ||
| Base URL: {{BASE_URL}} | ||
| </Template>`; | ||
|
|
||
| const result = convertToLlmTxtMarkdown(markdown, "Test Page", "mdx"); | ||
|
|
||
| expect(result).toContain("# Test Page"); | ||
| expect(result).toContain("Use your API key: test-key-123"); | ||
| expect(result).toContain("Base URL: https://api.example.com"); | ||
| expect(result).not.toContain("<Template"); | ||
| expect(result).not.toContain("{{API_KEY}}"); | ||
| expect(result).not.toContain("{{BASE_URL}}"); | ||
| }); | ||
|
|
||
| it("should apply global template variables", () => { | ||
| const markdown = `# Test | ||
|
|
||
| Your free credits threshold is {{FREE_MODEL_CREDITS_THRESHOLD}}. | ||
| Use API key: {{API_KEY_REF}}`; | ||
|
|
||
| const result = convertToLlmTxtMarkdown(markdown, "Test Page", "mdx"); | ||
|
|
||
| expect(result).toContain("# Test Page"); | ||
| expect(result).toContain("Your free credits threshold is 10"); | ||
| expect(result).toContain("Use API key: your-api-key"); | ||
| expect(result).not.toContain("{{FREE_MODEL_CREDITS_THRESHOLD}}"); | ||
| expect(result).not.toContain("{{API_KEY_REF}}"); | ||
| }); | ||
|
|
||
| it("should handle mixed content with multiple component types", () => { | ||
| const markdown = `# Mixed Content Test | ||
|
|
||
| Regular markdown paragraph. | ||
|
|
||
| <TSFetchCodeBlock> | ||
| const apiKey = "{{API_KEY_REF}}"; | ||
| </TSFetchCodeBlock> | ||
|
|
||
| <Template data={{"USER_NAME": "Alice"}}> | ||
| Hello {{USER_NAME}}! | ||
| </Template> | ||
|
|
||
| <CodeGroup> | ||
| <Code language="bash"> | ||
| curl -H "Authorization: Bearer {{API_KEY_REF}}" | ||
| </Code> | ||
| </CodeGroup> | ||
|
|
||
| More regular content with {{FREE_MODEL_CREDITS_THRESHOLD}} credits.`; | ||
|
|
||
| const result = convertToLlmTxtMarkdown(markdown, "Mixed Test", "mdx"); | ||
|
|
||
| expect(result).toContain("# Mixed Test"); | ||
| expect(result).toContain("Regular markdown paragraph."); | ||
| expect(result).toContain("```typescript"); | ||
| expect(result).toContain('const apiKey = "your-api-key";'); | ||
| expect(result).toContain("Hello Alice!"); | ||
| expect(result).toContain("```bash"); | ||
| expect(result).toContain('curl -H "Authorization: Bearer your-api-key"'); | ||
| expect(result).toContain("More regular content with 10 credits."); | ||
|
|
||
| expect(result).not.toContain("<TSFetchCodeBlock>"); | ||
| expect(result).not.toContain("<Template"); | ||
| expect(result).not.toContain("<CodeGroup>"); | ||
| expect(result).not.toContain("{{"); | ||
| }); | ||
|
|
||
| it("should handle empty or malformed components gracefully", () => { | ||
| const markdown = `# Edge Cases | ||
|
|
||
| <TSFetchCodeBlock></TSFetchCodeBlock> | ||
|
|
||
| <CodeGroup></CodeGroup> | ||
|
|
||
| <Template></Template> | ||
|
|
||
| Regular content continues.`; | ||
|
|
||
| const result = convertToLlmTxtMarkdown(markdown, "Edge Cases", "mdx"); | ||
|
|
||
| expect(result).toContain("# Edge Cases"); | ||
| expect(result).toContain("Regular content continues."); | ||
| expect(result).not.toContain("<TSFetchCodeBlock>"); | ||
| expect(result).not.toContain("<CodeGroup>"); | ||
| expect(result).not.toContain("<Template>"); | ||
| }); | ||
|
|
||
| it("should preserve content when format is 'md' instead of 'mdx'", () => { | ||
| const markdown = `# Test | ||
|
|
||
| <TSFetchCodeBlock> | ||
| console.log("test"); | ||
| </TSFetchCodeBlock>`; | ||
|
|
||
| const result = convertToLlmTxtMarkdown(markdown, "Test Page", "md"); | ||
|
|
||
| expect(result).toContain("# Test Page"); | ||
| expect(result).toContain("<TSFetchCodeBlock>"); | ||
| }); | ||
|
|
||
| it("should handle TSFetchCodeBlock with src attribute", () => { | ||
| const markdown = `# Test | ||
|
|
||
| <TSFetchCodeBlock src="https://example.com/code.ts"> | ||
| </TSFetchCodeBlock>`; | ||
|
|
||
| const result = convertToLlmTxtMarkdown(markdown, "Test Page", "mdx"); | ||
|
|
||
| expect(result).toContain("# Test Page"); | ||
| expect(result).toContain("```typescript"); | ||
| expect(result).toContain("// Code from: https://example.com/code.ts"); | ||
| expect(result).not.toContain("<TSFetchCodeBlock>"); | ||
| }); | ||
|
|
||
| it("should extract title and description from frontmatter", () => { | ||
| const markdown = `--- | ||
| title: "Custom Title" | ||
| description: "Custom description" | ||
| --- | ||
|
|
||
| # Heading | ||
|
|
||
| Content here.`; | ||
|
|
||
| const result = convertToLlmTxtMarkdown(markdown, "Default Title", "md"); | ||
|
|
||
| expect(result).toContain("# Custom Title"); | ||
| expect(result).toContain("> Custom description"); | ||
| expect(result).toContain("Content here."); | ||
| }); | ||
| }); | ||
| }); |
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
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is there anywhere we should be adding/modifying tests for this?