Skip to content

Commit 70ad31d

Browse files
committed
Fix quarto preview subdir/file.qmd crashing with doubled path
`quarto preview subdir/page.qmd` in a website project crashes with `readfile subdir\subdir\page.qmd`. The `projectPath` function was designed for output filenames (resolving relative to source directory via dirname+join), but was also called with the source path itself. When that source path was relative, dirname+join doubled the subdirectory. Split into two functions: `projectRelativeInput` for source paths (normalizes directly) and `projectOutputPath` for output filenames (preserves the dirname+join logic).
1 parent a18919f commit 70ad31d

1 file changed

Lines changed: 20 additions & 4 deletions

File tree

src/command/render/render.ts

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -385,8 +385,24 @@ export async function renderPandoc(
385385
));
386386
}
387387

388-
// if there is a project context then return paths relative to the project
389-
const projectPath = (path: string) => {
388+
// Compute the project-relative path for the input source file.
389+
// Uses normalizePath to handle both relative and absolute source paths.
390+
const projectRelativeInput = (sourcePath: string) => {
391+
if (context.project) {
392+
return relative(
393+
normalizePath(context.project.dir),
394+
normalizePath(sourcePath),
395+
);
396+
}
397+
return sourcePath;
398+
};
399+
400+
// Resolve an output file path to a project-relative path.
401+
// Output paths (like "page.html") are relative to the source file's
402+
// directory, so we join with dirname(target.source) before computing
403+
// the project-relative result. Absolute output paths pass through
404+
// normalizePath directly.
405+
const projectOutputPath = (path: string) => {
390406
if (context.project) {
391407
if (isAbsolute(path)) {
392408
return relative(
@@ -411,7 +427,7 @@ export async function renderPandoc(
411427

412428
const result: RenderedFile = {
413429
isTransient: recipe.isOutputTransient,
414-
input: projectPath(context.target.source),
430+
input: projectRelativeInput(context.target.source),
415431
markdown: executeResult.markdown,
416432
format,
417433
supporting: supporting
@@ -421,7 +437,7 @@ export async function renderPandoc(
421437
: undefined,
422438
file: recipe.isOutputTransient
423439
? finalOutput!
424-
: projectPath(finalOutput!),
440+
: projectOutputPath(finalOutput!),
425441
resourceFiles: {
426442
globs: pandocResult.resources,
427443
files,

0 commit comments

Comments
 (0)