Skip to content
Merged
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
25 changes: 25 additions & 0 deletions remote-content/remote-sources/repo-transforms.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ function applyBasicMdxFixes(content) {

return `:::${docusaurusType}\n${cleanContent}\n:::\n`;
})
// Fix HTML comments for MDX compatibility
.replace(/<!--\s*/g, '{/* ')
.replace(/\s*-->/g, ' */}')
// Fix HTML tags for MDX compatibility
.replace(/<br>/g, '<br />')
.replace(/<br([^/>]*?)>/g, '<br$1 />')
Expand Down Expand Up @@ -60,6 +63,28 @@ function resolvePath(path, sourceDir, repoUrl, branch) {
return `${repoUrl}/blob/${branch}/${rootPath}`;
}

// Handle complex relative paths with ../ navigation
if (cleanPath.includes('../')) {
// Split the source directory and the relative path
const sourceParts = sourceDir ? sourceDir.split('/') : [];
const pathParts = cleanPath.split('/');

// Process each part of the path
const resolvedParts = [...sourceParts];
for (const part of pathParts) {
if (part === '..') {
// Go up one directory
resolvedParts.pop();
} else if (part !== '.' && part !== '') {
// Add the directory/file part
resolvedParts.push(part);
}
}

const resolvedPath = resolvedParts.join('/');
return `${repoUrl}/blob/${branch}/${resolvedPath}`;
}

// Handle regular relative paths - these are relative to the source file's directory
const fullPath = sourceDir ? `${sourceDir}/${cleanPath}` : cleanPath;
return `${repoUrl}/blob/${branch}/${fullPath}`;
Expand Down