Skip to content

fix: keep fenced code blocks intact in llms.txt exports - #2562

Open
RaphaelFakhri wants to merge 1 commit into
expressjs:mainfrom
RaphaelFakhri:fix/llms-keep-code-block-imports
Open

RaphaelFakhri wants to merge 1 commit into
expressjs:mainfrom
RaphaelFakhri:fix/llms-keep-code-block-imports

Conversation

@RaphaelFakhri

Copy link
Copy Markdown

stripMdxSyntax() in src/utils/llms.ts removes MDX import statements and JSX tags with regular expressions that run over the whole file, including fenced code blocks. As a result, the /llms/*.txt exports drop code from examples:

  • Every ESM example loses its import lines. For example, the first index.mjs sample in /llms/api-5x.txt starts with an empty line instead of import express from 'express';.
  • Code that looks like a JSX tag is removed, for example Description=<Awesome Express App> in the systemd unit on the performance best practices page, and the <Alert> usage examples in the blog post guide.

This change sets fenced code blocks (backtick or tilde, optionally indented) aside before stripping MDX syntax and puts them back unchanged afterwards. Prose is processed exactly as before.

Testing

  • Adds tests/unit/llms.test.mjs. Without the fix, 2 of its 3 tests fail. With the fix, all 3 pass.
  • npm run test:unit: 68 tests pass.
  • Running getRawMarkdown() before and after the change over every file in src/content: the only differences are lines inside fenced code blocks, which now match the source (2,420 restored import lines, plus the cases listed above).

Fixes #2561

@RaphaelFakhri
RaphaelFakhri requested a review from a team as a code owner November 3, 2026 12:39
@netlify

netlify Bot commented Nov 3, 2026 •

Copy link
Copy Markdown

✅ Deploy Preview for expressjscom-preview ready!

Name Link
🔨 Latest commit 24b8a6b
🔍 Latest deploy log https://app.netlify.com/projects/expressjscom-preview/deploys/6ae9d60d6d952f94c9a1b53d
😎 Deploy Preview https://deploy-preview-2562--expressjscom-preview.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.
Lighthouse
Lighthouse
1 paths audited
Performance: 94 (🔴 down 3 from production)
Accessibility: 100 (no change from production)
Best Practices: 100 (no change from production)
SEO: 100 (no change from production)
PWA: 80 (no change from production)
View the detailed breakdown and full score reports
🤖 Make changes Run an agent on this branch

To edit notification comments on pull requests, go to your Netlify project configuration.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

llms.txt exports drop import lines and JSX-like code from code examples

1 participant