docs: mdx, light/dark mode, ask (#400)

This commit is contained in:
Chris Tate
2026-02-09 11:16:21 -06:00
committed by GitHub
parent 4d8097a56f
commit e8ceafcbe1
36 changed files with 4221 additions and 1258 deletions
+54
View File
@@ -0,0 +1,54 @@
/**
* Converts raw MDX content to clean Markdown suitable for AI agents.
*
* Transformations:
* - Remove `export` statements (metadata, etc.)
* - Remove `import` statements
* - Strip standalone JSX divs with className attributes
* - Pass everything else through as-is (already valid Markdown)
*/
export function mdxToCleanMarkdown(raw: string): string {
const lines = raw.split("\n");
const out: string[] = [];
let inJsxBlock = false;
let jsxDepth = 0;
for (const line of lines) {
const trimmed = line.trim();
// Skip export and import statements
if (trimmed.startsWith("export ") || trimmed.startsWith("import ")) {
continue;
}
// Track JSX blocks (like callout divs) and skip them
if (
!inJsxBlock &&
trimmed.startsWith("<div ") &&
trimmed.includes("className=")
) {
inJsxBlock = true;
jsxDepth = 1;
continue;
}
if (inJsxBlock) {
// Count opening/closing div tags to handle nesting
const opens = (line.match(/<div[\s>]/g) || []).length;
const closes = (line.match(/<\/div>/g) || []).length;
jsxDepth += opens - closes;
if (jsxDepth <= 0) {
inJsxBlock = false;
jsxDepth = 0;
}
continue;
}
out.push(line);
}
// Clean up leading blank lines
let result = out.join("\n");
result = result.replace(/^\n+/, "\n").trim();
return result;
}