Composio powers 1000+ toolkits, tool search, context management, authentication, and a sandboxed workbench to help you build AI agents that turn intent into action.
fix(docs): scope twoslash stripping to code blocks only
Extract twoslash annotation stripping into dedicated function that only processes content inside code blocks (```...```), ensuring we don't accidentally modify any prose content. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Sushmithamallesh committed
Feb 4, 2026 at 16:41 UTC
67c07b45658be3aad0925c2595f695258448b218
1 file changed
+23
-10
docs/lib/source.ts
+23
-10
@@ -278,21 +278,34 @@ export function mdxToCleanMarkdown(content: string): string {
278
// Clean up excessive newlines
279
result = result.replace(/\n{3,}/g, '\n\n');
280
281
- // Strip twoslash annotations from code blocks (used for type-checking, not useful for AI)
281
+ // Strip twoslash annotations ONLY inside code blocks (used for type-checking, not useful for AI)
282
// These include: // ---cut---, // @errors, // ^?, // @noErrors, etc.
283
- result = result.replace(/^\/\/\s*---cut---.*$/gm, '');
284
- result = result.replace(/^\/\/\s*@errors?:.*$/gm, '');
285
- result = result.replace(/^\/\/\s*@noErrors.*$/gm, '');
286
- result = result.replace(/^\/\/\s*@filename:.*$/gm, '');
287
- result = result.replace(/^\/\/\s*@highlight.*$/gm, '');
288
- result = result.replace(/^\/\/\s*\^[\?\!].*$/gm, ''); // ^? and ^! hover annotations
289
-
290
- // Clean up any resulting empty lines in code blocks
291
- result = result.replace(/\n{3,}/g, '\n\n');
283
+ result = stripTwoslashFromCodeBlocks(result);
284
285
return result.trim();
286
}
287
288
+/**
289
+ * Strip twoslash annotations only from inside code blocks.
290
+ * This ensures we don't accidentally modify prose content.
291
+ */
292
+function stripTwoslashFromCodeBlocks(content: string): string {
293
+ // Match code blocks: ```lang ... ```
294
+ return content.replace(/(```[\w]*\n)([\s\S]*?)(```)/g, (match, open, code, close) => {
295
+ let cleanCode = code;
296
+ // Remove twoslash directives
297
+ cleanCode = cleanCode.replace(/^\/\/\s*---cut---.*\n?/gm, '');
298
+ cleanCode = cleanCode.replace(/^\/\/\s*@errors?:.*\n?/gm, '');
299
+ cleanCode = cleanCode.replace(/^\/\/\s*@noErrors.*\n?/gm, '');
300
+ cleanCode = cleanCode.replace(/^\/\/\s*@filename:.*\n?/gm, '');
301
+ cleanCode = cleanCode.replace(/^\/\/\s*@highlight.*\n?/gm, '');
302
+ cleanCode = cleanCode.replace(/^\/\/\s*\^[\?\!].*\n?/gm, ''); // ^? and ^! hover annotations
303
+ // Clean up resulting empty lines at start of code block
304
+ cleanCode = cleanCode.replace(/^\n+/, '');
305
+ return open + cleanCode + close;
306
+ });
307
+}
308
+
309
export async function getLLMText(page: InferPageType<typeof source>) {
310
// Fall back to description if getText is not available
311
if (typeof page.data.getText !== 'function') {