-
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
base: app
Are you sure you want to change the base?
Conversation
- Add expandMdxComponents function to convert custom components to markdown - Handle TSFetchCodeBlock, CodeGroup, and Template components - Apply template variable replacement using existing applyTemplates function - Process components before stripping MDX features in convertToLlmTxtMarkdown - Support global template variables like FREE_MODEL_CREDITS_THRESHOLD - Maintain backward compatibility with existing markdown processing Co-Authored-By: sam <[email protected]>
🤖 Devin AI EngineerI'll be helping with this pull request! Here's what you should know: ✅ I will automatically:
Note: I can only respond to comments from users who have write access to this repository. ⚙️ Control Options:
|
| `# ${title}`, | ||
| description != null ? `> ${description}` : undefined, | ||
| stripMdxFeatures(content, format), | ||
| stripMdxFeatures(expandMdxComponents(content, format), format), |
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?
|
Great question! Yes, we should definitely add tests for the new I'll add a new test file
Let me add those tests now and push an update to the PR. |
Test Coverage Analysis & RecommendationsAfter analyzing the codebase, here are my recommendations for test coverage: 🎯 Primary Test Location**** - New test file for the core functionality Test Coverage Should Include:
🧪 Test Cases to CoverComponent Expansion: // TSFetchCodeBlock expansion
'<TSFetchCodeBlock>console.log("test")</TSFetchCodeBlock>'
→ proper code block with TypeScript syntax
// CodeGroup expansion
'<CodeGroup><Code language="js">code1</Code><Code language="py">code2</Code></CodeGroup>'
→ multiple sequential code blocks
// Template expansion
'<Template data={{"API_KEY": "test-key"}}>Use {{API_KEY}}</Template>'
→ 'Use test-key'Edge Cases:
🔗 Integration Test Locations**** - Test the integration point
Route-level testing (optional but recommended):
📋 Existing Test Patterns to FollowLooking at
🚨 Note on Test EnvironmentThe existing test files show TypeScript configuration issues (missing Jest types), which suggests the test environment may need setup. This is consistent with the pre-existing compilation errors I encountered. 💡 RecommendationStart with |
- Test expandMdxComponents function with various MDX inputs - Test TSFetchCodeBlock, CodeGroup, and Template component expansion - Test global template variable replacement - Test edge cases and malformed components - Test backward compatibility with non-MDX content - Cover integration with convertToLlmTxtMarkdown function Co-Authored-By: sam <[email protected]>
Fix MDX Component Expansion in Markdown Routes
Problem
OpenRouter's documentation uses custom MDX components like
<TSFetchCodeBlock>,<CodeGroup>, and<Template>along with template variables like{FREE_MODEL_CREDITS_THRESHOLD}. However, the current fern-platform markdown processing pipeline strips these components without expanding them, resulting in raw component tags and unexpanded variables appearing in both the/markdownand/llms-full.txtroutes.This makes the generated content less useful for LLM consumption and breaks the intended dynamic behavior of the documentation.
Solution
This PR implements a new
expandMdxComponentsfunction that processes custom MDX components before the existingstripMdxFeaturesfunction runs. The solution:Key Changes
Added
expandMdxComponentsfunction insrc/server/llm-txt-md.tsthat:<TSFetchCodeBlock>components to proper code blocks with TypeScript syntax highlighting<CodeGroup>components into multiple sequential code blocks with appropriate headers<Template>components by applying template variable replacement using the existingapplyTemplatesfunctionUpdated
convertToLlmTxtMarkdownfunction to callexpandMdxComponentsbeforestripMdxFeatures:Leveraged existing infrastructure:
applyTemplatesfunction fromTemplate.tsxtoTree,visit,mdastToMarkdown)Component Handling
{{variable}}syntaxFREE_MODEL_CREDITS_THRESHOLD,API_KEY_REF, etc.Testing
llm-txt-md.tswith proper TypeScript typesapplyTemplatesfunction to avoid code duplicationImpact
This change will make OpenRouter's documentation more useful for LLM consumption by:
/llms-full.txtendpoint for AI applicationsLink to Devin run
https://app.devin.ai/sessions/80e140ec2e604be5b1aec7676f15fcb5
Requested by
sam ([email protected])