Skip to content

Commit 34a7bab

Browse files
committed
use relative paths but allow absolute paths
1 parent 5dc8d51 commit 34a7bab

File tree

2 files changed

+16
-5
lines changed

2 files changed

+16
-5
lines changed

src/core/handlers/include.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,9 @@ const includeHandler: LanguageHandler = {
4949
);
5050
}
5151

52-
const notebookAddress = parseNotebookAddress(path);
52+
const notebookAddress = parseNotebookAddress(filename);
5353
if (notebookAddress) {
54-
const placeHolder = notebookMarkdownPlaceholder(path, {});
54+
const placeHolder = notebookMarkdownPlaceholder(filename, {});
5555
textFragments.push(placeHolder);
5656
} else {
5757
let includeSrc;

src/core/jupyter/jupyter-embed.ts

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,13 +33,14 @@ import { resolveParams } from "../../command/render/flags.ts";
3333
import { RenderContext, RenderFlags } from "../../command/render/types.ts";
3434
import { JupyterAssets, JupyterCellOutput } from "../jupyter/types.ts";
3535

36-
import { dirname, extname } from "path/mod.ts";
36+
import { dirname, extname, join } from "path/mod.ts";
3737
import { languages } from "../handlers/base.ts";
3838
import {
3939
extractJupyterWidgetDependencies,
4040
includesForJupyterWidgetDependencies,
4141
} from "./widgets.ts";
4242
import { globalTempContext } from "../temp.ts";
43+
import { isAbsolute } from "https://deno.land/[email protected]/path/win32.ts";
4344

4445
export interface JupyterNotebookAddress {
4546
path: string;
@@ -158,7 +159,7 @@ export async function replaceNotebookPlaceholders(
158159
);
159160

160161
const notebookIncludes = () => {
161-
const notebook = jupyterFromFile(nbAddress.path);
162+
const notebook = jupyterFromFile(resolveNbPath(input, nbAddress.path));
162163
const dependencies = isHtmlOutput(context.format.pandoc)
163164
? extractJupyterWidgetDependencies(notebook)
164165
: undefined;
@@ -196,6 +197,14 @@ export async function replaceNotebookPlaceholders(
196197
};
197198
}
198199

200+
function resolveNbPath(input: string, path: string) {
201+
if (isAbsolute(path)) {
202+
return path;
203+
} else {
204+
return join(dirname(input), path);
205+
}
206+
}
207+
199208
async function notebookMarkdown(
200209
nbAddress: JupyterNotebookAddress,
201210
assets: JupyterAssets,
@@ -282,7 +291,9 @@ async function getCellOutputs(
282291
if (!nbCache.cache[cacheKey]) {
283292
// Render the notebook and place it in the cache
284293
// Read and filter notebook
285-
const notebook = jupyterFromFile(nbAddress.path);
294+
const notebook = jupyterFromFile(
295+
resolveNbPath(context.target.input, nbAddress.path),
296+
);
286297
if (options) {
287298
notebook.cells = notebook.cells.map((cell) => {
288299
if (options.echo !== undefined) {

0 commit comments

Comments
 (0)