Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 13 additions & 6 deletions bin/dory.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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!');
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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": [
Expand Down
35 changes: 30 additions & 5 deletions src/plugins/sanitize.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 <tag> and </tag> 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('</')) {
if (!hasMatchingClosingTag(processed, tag, offset)) {
return `\`${match}\``;
}
}
// 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
const before = processed.slice(0, offset);
const backtickMatches = before.match(/`+/g);
const insideBackticks = backtickMatches ? backtickMatches.reduce((acc, s) => acc + s.length, 0) % 2 === 1 : false;
if (insideBackticks) {
return match;
}
return `\`${match}\``;
});

return {
code: processed,
map: null,
Expand Down