diff --git a/bin/dory.js b/bin/dory.js index 8d193ef..6d18af4 100755 --- a/bin/dory.js +++ b/bin/dory.js @@ -14,15 +14,21 @@ const commands = { build: () => { console.log('๐ŸŸ Dory is ready to build your docs!'); - // Clear the docs folder if it exists - const docsDir = resolve(__dirname, '..', 'docs'); + const currentDir = process.cwd(); + const userDocsDir = resolve(currentDir, 'docs'); + const hasUserDocs = existsSync(userDocsDir); + + // Use different temp directory if user has their own docs folder + const tempDirName = hasUserDocs ? '.dory-build-temp' : 'docs'; + const docsDir = resolve(__dirname, '..', tempDirName); + + // Clear the temp build folder if it exists if (existsSync(docsDir)) { console.log('๐Ÿงน Tidying up the workspace...'); rmSync(docsDir, { recursive: true, force: true }); } // Check if dory.json exists in current directory - const currentDir = process.cwd(); const doryConfigPath = resolve(currentDir, 'dory.json'); if (!existsSync(doryConfigPath)) { @@ -53,8 +59,9 @@ const commands = { } }; - // Copy all files and directories except node_modules, dist, and .git - const excludeDirs = ['node_modules', 'dist', '.git', 'docs', 'pnpm-lock.yaml']; + // Copy all files and directories except node_modules, dist, .git, and temp build dir + // Don't exclude 'docs' if user has their own docs folder - we need to copy it + const excludeDirs = ['node_modules', 'dist', '.git', 'pnpm-lock.yaml', tempDirName]; const items = readdirSync(currentDir); for (const item of items) { @@ -88,7 +95,7 @@ const commands = { } rmSync(distDir, { recursive: true, force: true }); - // Revert docs folder back to original state + // Clean up temp build folder (but preserve user's docs folder if it exists) console.log('๐Ÿงน Cleaning up...'); rmSync(docsDir, { recursive: true, force: true }); console.log('โœ… All done!'); diff --git a/package.json b/package.json index b28ed17..a003f98 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "@clidey/dory", "private": false, - "version": "0.16.0", + "version": "0.17.0", "type": "module", "description": "A CLI tool for building and previewing documentation sites", "keywords": [ diff --git a/src/plugins/sanitize.ts b/src/plugins/sanitize.ts index 09fed56..d54a79f 100644 --- a/src/plugins/sanitize.ts +++ b/src/plugins/sanitize.ts @@ -100,21 +100,46 @@ export function preprocessMdxTags() { // Otherwise, leave as-is for proper JSX parsing return match; } - + // For unknown components, always treat as text (wrap in backticks) // If already inside backticks, do not wrap again - // Find the start of the line up to the match const before = processed.slice(0, offset); - // Count the number of backticks before this tag const backtickMatches = before.match(/`+/g); - // If the number of backticks is odd, we're inside a backtick span const insideBackticks = backtickMatches ? backtickMatches.reduce((acc, s) => acc + s.length, 0) % 2 === 1 : false; if (insideBackticks) { return match; } - // Otherwise, wrap in backticks to prevent JSX parsing return `\`<${tag}>\``; }); + // This regex finds all and occurrences + processed = processed.replace(/<\/?([a-z][a-z0-9]*)>/gi, (match, tag, offset) => { + // If inside a code block, do not touch + if (isInsideCodeBlock(processed, offset)) { + return match; + } + + // If known component, check if it has a closing tag (only for opening tags) + if (KNOWN_COMPONENTS.includes(tag)) { + // Only check for matching closing tag for opening tags + if (!match.startsWith(' acc + s.length, 0) % 2 === 1 : false; + if (insideBackticks) { + return match; + } + return `\`${match}\``; + }); + return { code: processed, map: null,