Skip to content

Commit 03766fe

Browse files
committed
use .out. meta-extension if output will overwrite input
1 parent e67e3ac commit 03766fe

File tree

1 file changed

+20
-2
lines changed

1 file changed

+20
-2
lines changed

src/command/render/output.ts

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,14 @@
55
*
66
*/
77

8-
import { dirname, extname, isAbsolute, join, relative } from "path/mod.ts";
8+
import {
9+
basename,
10+
dirname,
11+
extname,
12+
isAbsolute,
13+
join,
14+
relative,
15+
} from "path/mod.ts";
916

1017
import { writeFileToStdout } from "../../core/console.ts";
1118
import { dirAndStem, expandPath } from "../../core/path.ts";
@@ -140,7 +147,18 @@ export function outputRecipe(
140147
if (extname(input) === ".md" && ext === "md") {
141148
outputExt = `${format.pandoc.to}.md`;
142149
}
143-
updateOutput(inputStem + "." + outputExt);
150+
151+
// derive new output file
152+
let output = inputStem + "." + outputExt;
153+
154+
// special case if the source will overwrite the destination (note: this
155+
// behavior can be customized with a custom output-ext)
156+
if (output === basename(context.target.source)) {
157+
output = inputStem + ".out." + outputExt;
158+
}
159+
160+
// assign output
161+
updateOutput(output);
144162
} else if (recipe.output === kStdOut) {
145163
// output to stdout: direct pandoc to write to a temp file then we'll
146164
// forward to stdout (necessary b/c a postprocesor may need to act on

0 commit comments

Comments
 (0)