Conversation
📝 WalkthroughWalkthroughAdds a preprocess pipeline for files: MDX validation, Mintlify-specific transforms (title fallback + plain-URL wrapping), and sanitization; integrates this pipeline into file aggregation, introduces a wrapPlainUrls utility with tests, and adds a changeset documenting the patch. Changes
Sequence Diagram(s)sequenceDiagram
autonumber
participant CLI as "CLI aggregator"
participant Pre as "preprocessContent"
participant MDX as "preprocessMdx (validator)"
participant Mint as "preprocessMintlify"
participant Wrap as "wrapPlainUrls"
participant Sanit as "sanitizeFileContent"
participant Store as "FileToUpload"
CLI->>Pre: send (content, path, type, settings)
Pre->>MDX: if type === 'mdx' validate content
alt MDX invalid
MDX-->>Pre: return skip reason
Pre-->>CLI: return { skip }
else MDX valid
MDX-->>Pre: ok
Pre->>Mint: if settings.framework === 'mintlify' transform content
Mint->>Wrap: (for mdx) wrap plain URLs
Wrap-->>Mint: transformed content
Mint-->>Pre: transformed content
Pre->>Sanit: sanitize transformed content
Sanit-->>Pre: sanitized content
Pre-->>Store: provide sanitized content for FileToUpload (versionId from original content)
Store-->>CLI: file prepared
end
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Poem
🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches
🧪 Generate unit tests (beta)
Comment |
There was a problem hiding this comment.
🧹 Nitpick comments (2)
packages/cli/src/utils/wrapPlainUrls.ts (2)
19-26: Minor:runSyncmay be unnecessary.Since no remark transformers are configured (only parsers),
processor.runSync(ast)doesn't modify the AST. You could simplify to just usingprocessor.parse(content)and skip therunSynccall.This is a minor optimization and doesn't affect correctness.
♻️ Proposed simplification
- ast = processor.parse(content); - ast = processor.runSync(ast) as Root; + ast = processor.parse(content) as Root;🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@packages/cli/src/utils/wrapPlainUrls.ts` around lines 19 - 26, The code calls processor.runSync(ast) after parsing, but since no remark transformers are configured the AST is unchanged; remove the unnecessary runSync call and set ast directly from the parse result (i.e., replace the pattern where ast = processor.parse(content); ast = processor.runSync(ast) with a single assignment using processor.parse(content) (cast to Root if needed) and remove the processor.runSync invocation and its assignment.
8-8: Regex edge case: URLs with balanced parentheses may be truncated.URLs like
https://en.wikipedia.org/wiki/Example_(disambiguation)will be cut at the first(because parentheses are excluded from the URL character class. This is a known limitation of simple regex-based URL detection.If Mintlify content includes Wikipedia-style URLs or URLs with parentheses in paths, consider documenting this limitation or enhancing the regex to handle balanced parentheses.
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@packages/cli/src/utils/wrapPlainUrls.ts` at line 8, The current URL_REGEX excludes parentheses so URLs with balanced parentheses (e.g., Wikipedia-style paths) get truncated; update the match logic by allowing '(' and ')' in the character class for URL_REGEX and add a small post-processing step in the wrapping function to ensure parentheses are balanced (if the match ends with a ')' but there are more closing than opening parens, trim the trailing ')' until balanced) — alternatively, replace the simplistic regex approach with a URL parser or a third-party URL-detection library if you prefer robustness; reference URL_REGEX in wrapPlainUrls.ts and add the balancing fix in the code that consumes URL_REGEX matches.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Nitpick comments:
In `@packages/cli/src/utils/wrapPlainUrls.ts`:
- Around line 19-26: The code calls processor.runSync(ast) after parsing, but
since no remark transformers are configured the AST is unchanged; remove the
unnecessary runSync call and set ast directly from the parse result (i.e.,
replace the pattern where ast = processor.parse(content); ast =
processor.runSync(ast) with a single assignment using processor.parse(content)
(cast to Root if needed) and remove the processor.runSync invocation and its
assignment.
- Line 8: The current URL_REGEX excludes parentheses so URLs with balanced
parentheses (e.g., Wikipedia-style paths) get truncated; update the match logic
by allowing '(' and ')' in the character class for URL_REGEX and add a small
post-processing step in the wrapping function to ensure parentheses are balanced
(if the match ends with a ')' but there are more closing than opening parens,
trim the trailing ')' until balanced) — alternatively, replace the simplistic
regex approach with a URL parser or a third-party URL-detection library if you
prefer robustness; reference URL_REGEX in wrapPlainUrls.ts and add the balancing
fix in the code that consumes URL_REGEX matches.
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: 76faeeab-0abe-4639-b2c9-794c160173fd
⛔ Files ignored due to path filters (1)
packages/cli/src/generated/version.tsis excluded by!**/generated/**
📒 Files selected for processing (4)
.changeset/tasty-rockets-rule.mdpackages/cli/src/formats/files/aggregateFiles.tspackages/cli/src/utils/__tests__/wrapPlainUrls.test.tspackages/cli/src/utils/wrapPlainUrls.ts
There was a problem hiding this comment.
🧹 Nitpick comments (1)
packages/cli/src/formats/files/preprocess/mintlify.ts (1)
1-32: Consider consolidating thefileType === 'mdx'checks.The two separate
if (fileType === 'mdx')blocks could be combined for cleaner control flow, especially ifmdsupport is added.♻️ Proposed consolidation
export function preprocessMintlify( content: string, filePath: string, fileType: string, settings: Settings ): string { let result = content; - if ( - fileType === 'mdx' && - settings.options?.mintlify?.inferTitleFromFilename - ) { - result = applyMintlifyTitleFallback( - result, - filePath, - settings.defaultLocale - ).content; - } - - if (fileType === 'mdx') { - result = wrapPlainUrls(result); + if (fileType === 'mdx' || fileType === 'md') { + if (fileType === 'mdx' && settings.options?.mintlify?.inferTitleFromFilename) { + result = applyMintlifyTitleFallback( + result, + filePath, + settings.defaultLocale + ).content; + } + result = wrapPlainUrls(result); } return result; }🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@packages/cli/src/formats/files/preprocess/mintlify.ts` around lines 1 - 32, Consolidate the two separate fileType checks inside preprocessMintlify by combining them into a single conditional (e.g., check fileType === 'mdx' or other future types) and then run applyMintlifyTitleFallback only when settings.options?.mintlify?.inferTitleFromFilename is true and always run wrapPlainUrls for that fileType; update preprocessMintlify to perform the single fileType guard and inside it call applyMintlifyTitleFallback (when needed) and wrapPlainUrls so control flow is simpler and easier to extend (refer to preprocessMintlify, applyMintlifyTitleFallback, and wrapPlainUrls).
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Nitpick comments:
In `@packages/cli/src/formats/files/preprocess/mintlify.ts`:
- Around line 1-32: Consolidate the two separate fileType checks inside
preprocessMintlify by combining them into a single conditional (e.g., check
fileType === 'mdx' or other future types) and then run
applyMintlifyTitleFallback only when
settings.options?.mintlify?.inferTitleFromFilename is true and always run
wrapPlainUrls for that fileType; update preprocessMintlify to perform the single
fileType guard and inside it call applyMintlifyTitleFallback (when needed) and
wrapPlainUrls so control flow is simpler and easier to extend (refer to
preprocessMintlify, applyMintlifyTitleFallback, and wrapPlainUrls).
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: 81d5cc11-0440-4728-af1c-b36363133b1b
📒 Files selected for processing (5)
packages/cli/src/formats/files/__tests__/aggregateFiles.test.tspackages/cli/src/formats/files/aggregateFiles.tspackages/cli/src/formats/files/preprocess/mdx.tspackages/cli/src/formats/files/preprocess/mintlify.tspackages/cli/src/formats/files/preprocessContent.ts
🚧 Files skipped from review as they are similar to previous changes (1)
- packages/cli/src/formats/files/aggregateFiles.ts
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@packages/cli/src/formats/files/preprocess/mintlify.ts`:
- Around line 14-27: The early return only allows 'mdx' files through, skipping
wrapPlainUrls for '.md' files; update the guard in the preprocessing block so
both 'mdx' and 'md' are processed (e.g., change the fileType check around the
if/return that currently references 'mdx') so applyMintlifyTitleFallback and
wrapPlainUrls run for markdown (.md) as well — reference the variables/fileType,
content, settings, applyMintlifyTitleFallback, and wrapPlainUrls to locate and
adjust the condition.
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: 93a3e6e1-2f8c-4d82-9ae5-a459b505d2ed
📒 Files selected for processing (1)
packages/cli/src/formats/files/preprocess/mintlify.ts
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@packages/cli/src/utils/wrapPlainUrls.ts`:
- Around line 35-37: The check that skips text nodes inside links currently only
checks for parent.type === 'link' and misses reference-style links; update the
condition in wrapPlainUrls (the parent check near the top of the transformer) to
also treat parent.type === 'linkReference' as already-linked (e.g. if (parent &&
(parent.type === 'link' || parent.type === 'linkReference')) return;), so text
nodes inside reference links are not rewrapped.
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: ddc30301-86ff-4fb2-8644-59505ff5b56b
📒 Files selected for processing (2)
packages/cli/src/utils/__tests__/wrapPlainUrls.test.tspackages/cli/src/utils/wrapPlainUrls.ts
🚧 Files skipped from review as they are similar to previous changes (1)
- packages/cli/src/utils/tests/wrapPlainUrls.test.ts
| // Skip text nodes inside links — those are already display text for a link | ||
| if (parent && parent.type === 'link') return; | ||
|
|
There was a problem hiding this comment.
Skip linkReference content as already-linked text.
Line 36 only excludes link parents. In reference-style links (e.g. [https://x][id]), text nodes are under linkReference, so this can rewrap already-linked content.
Suggested patch
- if (parent && parent.type === 'link') return;
+ if (parent && (parent.type === 'link' || parent.type === 'linkReference')) return;📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| // Skip text nodes inside links — those are already display text for a link | |
| if (parent && parent.type === 'link') return; | |
| // Skip text nodes inside links — those are already display text for a link | |
| if (parent && (parent.type === 'link' || parent.type === 'linkReference')) return; |
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.
In `@packages/cli/src/utils/wrapPlainUrls.ts` around lines 35 - 37, The check that
skips text nodes inside links currently only checks for parent.type === 'link'
and misses reference-style links; update the condition in wrapPlainUrls (the
parent check near the top of the transformer) to also treat parent.type ===
'linkReference' as already-linked (e.g. if (parent && (parent.type === 'link' ||
parent.type === 'linkReference')) return;), so text nodes inside reference links
are not rewrapped.
This PR was opened by the [Changesets release](https://github.com/changesets/action) GitHub action. When you're ready to do a release, you can merge this and the packages will be published to npm automatically. If you're not ready to do a release yet, that's fine, whenever you add more changesets to main, this PR will be updated. # Releases ## gtx-cli@2.6.30 ### Patch Changes - [#1068](#1068) [`94b95ef`](94b95ef) Thanks [@ErnestM1234](https://github.com/ErnestM1234)! - fix: runtime calculation for the injection of 'data-' attribute in jsx - [#1066](#1066) [`7b4837f`](7b4837f) Thanks [@fernando-aviles](https://github.com/fernando-aviles)! - Wrapping text node URLs for Mintlify MDX to align with their parser ## @generaltranslation/compiler@1.1.23 ### Patch Changes - [#1068](#1068) [`94b95ef`](94b95ef) Thanks [@ErnestM1234](https://github.com/ErnestM1234)! - fix: runtime calculation for the injection of 'data-' attribute in jsx ## locadex@1.0.108 ### Patch Changes - Updated dependencies \[[`94b95ef`](94b95ef), [`7b4837f`](7b4837f)]: - gtx-cli@2.6.30 ## gt-next@6.13.3 ### Patch Changes - [#1068](#1068) [`94b95ef`](94b95ef) Thanks [@ErnestM1234](https://github.com/ErnestM1234)! - fix: runtime calculation for the injection of 'data-' attribute in jsx - Updated dependencies \[[`94b95ef`](94b95ef)]: - @generaltranslation/compiler@1.1.23 - gt-react@10.11.2 ## @generaltranslation/gt-next-lint@11.0.3 ### Patch Changes - Updated dependencies \[[`94b95ef`](94b95ef)]: - gt-next@6.13.3 ## gt-react@10.11.2 ### Patch Changes - Updated dependencies \[[`94b95ef`](94b95ef)]: - @generaltranslation/react-core@1.5.2 ## @generaltranslation/react-core@1.5.2 ### Patch Changes - [#1068](#1068) [`94b95ef`](94b95ef) Thanks [@ErnestM1234](https://github.com/ErnestM1234)! - fix: runtime calculation for the injection of 'data-' attribute in jsx ## @generaltranslation/react-core-linter@0.1.2 ### Patch Changes - [#1068](#1068) [`94b95ef`](94b95ef) Thanks [@ErnestM1234](https://github.com/ErnestM1234)! - fix: runtime calculation for the injection of 'data-' attribute in jsx ## gt-tanstack-start@0.1.9 ### Patch Changes - Updated dependencies \[[`94b95ef`](94b95ef)]: - @generaltranslation/react-core@1.5.2 - gt-react@10.11.2 ## gt-next-middleware-e2e@0.1.3 ### Patch Changes - Updated dependencies \[[`94b95ef`](94b95ef)]: - gt-next@6.13.3 Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Greptile Summary
This PR introduces a
wrapPlainUrlspreprocessing step for thegtx-clitool that converts bare URLs in text into Markdown link syntax ([url](url)) before uploading Mintlify MDX/MD files for translation. The transformation is applied only whenframework === 'mintlify'and uses AST-based parsing (viaremark/remark-mdx/remark-frontmatter) to target text nodes exclusively, correctly skipping URLs in code blocks, frontmatter, JSX attributes, existing markdown links, and HTML comments.Key changes:
packages/cli/src/utils/wrapPlainUrls.ts: AST-driven URL wrapper with fallback to original content on parse failure and reverse-order replacement to preserve character positions.aggregateFiles.ts: URL wrapping is gated onfileType === 'md' || fileType === 'mdx'andsettings.framework === 'mintlify', applied afterapplyMintlifyTitleFallbackand beforesanitizeFileContent.[^\s<>\[\]()]*excludes(from the middle of URL paths, causing URLs with parentheses (e.g. Wikipedia-stylehttps://en.wikipedia.org/wiki/Unix_(operating_system)) to be silently truncated. Because the function already uses AST parsing to ensure it only matches text nodes (never link hrefs), excluding(from the middle class is overly conservative and not required for correctness.Confidence Score: 3/5
aggregateFiles.tsis minimal and correctly scoped. However, the URL regex excludes(in the middle character class, which will incorrectly truncate valid URLs like Wikipedia links. Since this produces silently wrong output (a broken URL rather than a parse error), it warrants attention before merging to production Mintlify users who may have such links in their docs.packages/cli/src/utils/wrapPlainUrls.ts— theURL_REGEXon line 8 needs the parentheses exclusion revisited in its middle character class.Important Files Changed
(from the middle character class, causing URLs with parentheses in paths (e.g. Wikipedia links) to be truncated; module-level mutable regex withgflag also introduces subtle shared-state risk.md/mdxfiles withframework === 'mintlify', correctly after the title-fallback step and before sanitization. Integration looks clean.gtx-clidescribing the new Mintlify URL preprocessing step. Accurate and correctly scoped.Flowchart
%%{init: {'theme': 'neutral'}}%% flowchart TD A[aggregateFiles called] --> B{fileType is md or mdx?} B -- No --> G[sanitizeFileContent] B -- Yes --> C{framework === mintlify?} C -- No --> G C -- Yes --> D[wrapPlainUrls] subgraph wrapPlainUrls D --> E[Parse content with remark + remark-mdx + remark-frontmatter] E --> F{Parse succeeded?} F -- No --> R[Return content unchanged] F -- Yes --> H[visit AST text nodes] H --> I{Parent is link node?} I -- Yes --> J[Skip — already wrapped] I -- No --> K[Run URL_REGEX against node value] K --> L{Match found?} L -- Yes --> M[Record start/end offset + url] M --> K L -- No --> N[All text nodes visited] N --> O[Apply replacements in reverse offset order] O --> P[Return wrapped content] end P --> G[sanitizeFileContent] G --> Q[Upload FileToUpload with versionId from original content]Last reviewed commit: d058d69
Summary by CodeRabbit
Bug Fixes
New Features
Tests