fix(context): keep generics and JSX inside code when removing MDX tags - #173
Merged
Merged
Conversation
cleanMdxContent removed every <Name>-shaped token, including inside fenced blocks and inline code, so createTRPCClient<AppRouter>() was indexed as createTRPCClient(), List<String> as List, and <App /> vanished. Every such code line was lost in the four doc sets measured: NestJS 289, tRPC 298, Kysely 44, Drizzle 88. All are kept now. The tag regex now matches code first and keeps it whole: fences that open and close on a line of their own, closed by the same fence (an unclosed fence runs to the end, as in CommonMark), and inline code spans. createSection no longer runs cleanMdxContent again. Markdown is cleaned before it is split, and the second pass stripped generics from the later parts of a split code block. It also stripped them from AsciiDoc and rST sections only when they were long enough to split (JUnit lost 7 of 16 such lines, e.g. tasks.withType<Test>()).
🦋 Changeset detectedLatest commit: 3a700c6 The changes in this PR will be included in the next version bump. This PR includes changesets to release 2 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
Merged
moshest
pushed a commit
that referenced
this pull request
Sep 30, 2026
Releases @neuledge/context 1.2.9 -> 1.2.10 (patch). Consumes one changeset, .changeset/keep-code-generics.md (patch on @neuledge/context, from #173): generics and JSX inside code blocks and inline code are kept when MDX tags are removed. @neuledge/registry 0.0.22 -> 0.0.23 is the automatic dependent bump for the private workspace package. Verified before merging: npm dist-tags.latest is 1.2.9, and neither npm nor the MCP Registry has 1.2.10 yet.
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Problem
cleanMdxContentremoves MDX component tags such as<AppOnly>with the pattern<\/?[A-Z][a-zA-Z]*\s*\/?>. It also runs inside fenced code blocks and inline code. There the same shape is a generic type or a JSX example, so the index stores broken code:createTRPCClient<AppRouter>({createTRPCClient({this.configService.get<DatabaseConfig>('database')this.configService.get('database')export type Person = Selectable<PersonTable>export type Person = SelectableList<String> namesList namesroot.render(<App />)root.render()One tRPC example says "Pass AppRouter as a type parameter" right above a call that no longer has one.
I measured it by parsing four registry doc sets on
030918fand counting fenced code lines that contain a<Name>token:<Name>docs.nestjs.com/content)www/docs)site/docs)src/content/docs)Through the CLI (
context add <trpc>/www/docs), 45 tRPC chunks containcreateTRPCClient(and none containcreateTRPCClient<AppRouter>. With this PR, 43 chunks have the type parameter. The 3 without it are calls the docs really write that way.initTRPC.context<Context>goes from 0 chunks to 20.Fix
cleanMdxContentnow matches code first and keeps it whole. That covers fenced blocks (or ~~~) and inline code spans. A fence opens and closes only on a line of its own, and only the same fence closes it. So ainside a code line or a sentence does not pair with the next block. An unclosed fence runs to the end, as in CommonMark. Tags outside code are still removed.createSectionno longer runscleanMdxContenta second time. Markdown sections are already cleaned whole before they are split. A long code block split across parts has its opening fence in an earlier part, so the second pass stripped generics from the later parts. With only the first change, 47 of the 298 tRPC lines and 45 of the 289 NestJS lines were still missing.createSectionnow only trims.The second change also reaches AsciiDoc and reStructuredText. Their sections went through
cleanMdxContentonly when they were long enough to split. So a long section lost its generics and a short one kept them. In the JUnit docs 7 of 16 such lines were lost, includingtasks.withType<Test>(). Now none are.Not changed
.mdxfiles the same indentation is often nested JSX. Getting this right needs the parse tree, which is a bigger change.<Name>in plain prose, outside backticks, is still removed, as before.{/* ```sql ... ``` */}comments. The closing line``` */}opens a fence (it would in CommonMark too), so the rest of that section counts as code. As a result, 6 of Drizzle's 6,066 bare MDX tag lines, all</Section>, now stay in the index. Main removed all of them.splitAtParagraphsstill splits code blocks at blank lines. That is a separate chunking question.Test
Five tests. All fail on
030918fand pass with the fix:build.test.ts: fenced (``` and ~~~) and inline code keepcreateClient<AppRouter>(), `Promise`, `` and `List`, while `` is still removed.build.test.ts: fences pair by line and length. This covers ainside a code line, ain a sentence, a four-backtick fence around a ``` block, and an unclosed fence.build.test.ts: a code block split across section parts keeps the generic in its last part.build.test.ts: turndown output from HTML keepsOptional<User>in<code>andList<User>in<pre><code>.build.test.ts: an AsciiDoc section long enough to split keepsList<String>in every part.I broke each part of the fix in turn, and each time a test went red:
createSectionrunscleanMdxContentagainValidation
pnpm install --frozen-lockfile,pnpm lint,pnpm buildandpnpm testall pass: context 267 tests (262 before), registry 103..changeset/keep-code-generics.md(patch).