Skip to content

Commit 9eb2c74

Browse files
committed
Remove explicitly controlled output file
notebook-context is in charge of providing the output file
1 parent a9e9234 commit 9eb2c74

File tree

9 files changed

+21
-33
lines changed

9 files changed

+21
-33
lines changed

src/format/html/format-html-notebook-preview.ts

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -73,15 +73,13 @@ export const notebookPreviewer = (
7373
input: string,
7474
nbAbsPath: string,
7575
title?: string,
76-
nbPreviewFile?: string,
7776
callback?: (nbPreview: NotebookPreview) => void,
7877
) => {
7978
// Try to provide a title
8079
previewQueue.push({
8180
input,
8281
nbPath: nbAbsPath,
8382
title: title,
84-
nbPreviewFile,
8583
callback,
8684
});
8785
};
@@ -107,7 +105,7 @@ export const notebookPreviewer = (
107105
let renderCount = 0;
108106
for (let i = 0; i < total; i++) {
109107
const work = previewQueue[i];
110-
const { nbPath, input, title, nbPreviewFile } = work;
108+
const { nbPath, input, title } = work;
111109
if (
112110
toRenderPaths.includes(nbPath) && !haveRenderedPaths.includes(nbPath) &&
113111
!quiet
@@ -149,7 +147,6 @@ export const notebookPreviewer = (
149147
title: resolvedTitle,
150148
filename: basename(nbAbsPath),
151149
},
152-
undefined,
153150
project,
154151
);
155152
if (renderedIpynb && renderedIpynb.output && !project) {
@@ -180,7 +177,6 @@ export const notebookPreviewer = (
180177
downloadHref,
181178
downloadFile: basename(nbAbsPath),
182179
},
183-
nbPreviewFile,
184180
project,
185181
);
186182
if (htmlPreview.output && !project) {

src/format/html/format-html-notebook.ts

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,6 @@ export async function emplaceNotebookPreviews(
147147
input,
148148
input,
149149
undefined, // title
150-
undefined, // preview file name
151150
(nbPreview) => {
152151
// If this is a cell _in_ a source notebook, it will not be parented
153152
// by an embed cell
@@ -198,17 +197,11 @@ export async function emplaceNotebookPreviews(
198197
const title = nbDivEl.getAttribute("data-notebook-title");
199198
nbDivEl.removeAttribute("data-notebook-title");
200199

201-
const notebookPreviewFile = nbDivEl.getAttribute(
202-
"data-notebook-preview-file",
203-
);
204-
nbDivEl.removeAttribute("data-notebook-preview-file");
205-
206200
if (notebookPath) {
207201
previewer.enQueuePreview(
208202
input,
209203
nbAbsPath(input, notebookPath),
210204
title === null ? undefined : title,
211-
notebookPreviewFile === null ? undefined : notebookPreviewFile,
212205
(nbPreview) => {
213206
// Add a decoration to this div node
214207
if (inline) {

src/format/jats/format-jats-postprocess.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,6 @@ export const renderSubarticlePostProcessor = (
5656
kJatsSubarticle,
5757
services,
5858
undefined,
59-
undefined,
6059
project,
6160
);
6261
}

src/render/notebook/notebook-context.ts

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,7 @@
44
* Copyright (C) 2020-2022 Posit Software, PBC
55
*/
66

7-
import {
8-
ExecutedFile,
9-
RenderedFile,
10-
RenderServices,
11-
} from "../../command/render/types.ts";
7+
import { ExecutedFile, RenderServices } from "../../command/render/types.ts";
128
import { InternalError } from "../../core/lib/error.ts";
139
import { kJatsSubarticle } from "../../format/jats/format-jats-types.ts";
1410
import { ProjectContext } from "../../project/types.ts";
@@ -19,6 +15,7 @@ import {
1915
NotebookContext,
2016
NotebookContributor,
2117
NotebookMetadata,
18+
NotebookRenderResult,
2219
RenderType,
2320
} from "./notebook-types.ts";
2421

@@ -56,7 +53,7 @@ export function notebookContext(): NotebookContext {
5653
const addRendering = (
5754
nbAbsPath: string,
5855
renderType: RenderType,
59-
result: RenderedFile,
56+
result: NotebookRenderResult,
6057
) => {
6158
const absPath = join(dirname(nbAbsPath), basename(result.file));
6259
const output = {
@@ -151,7 +148,6 @@ export function notebookContext(): NotebookContext {
151148
renderType: RenderType,
152149
services: RenderServices,
153150
notebookMetadata?: NotebookMetadata,
154-
outputFile?: string,
155151
project?: ProjectContext,
156152
) => {
157153
addMetadata(nbAbsPath, renderType, notebookMetadata);
@@ -161,7 +157,6 @@ export function notebookContext(): NotebookContext {
161157
token(),
162158
services,
163159
notebookMetadata,
164-
outputFile,
165160
project,
166161
);
167162

src/render/notebook/notebook-contributor-html.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,6 @@ async function renderHtmlNotebook(
103103
_subArticleToken: string,
104104
services: RenderServices,
105105
notebookMetadata?: NotebookMetadata,
106-
outputFile?: string,
107106
project?: ProjectContext,
108107
): Promise<RenderedFile> {
109108
// Use the special `embed` template for this render
@@ -121,7 +120,7 @@ async function renderHtmlNotebook(
121120
metadata: {
122121
[kTo]: "html",
123122
[kTheme]: format.metadata[kTheme],
124-
[kOutputFile]: outputFile || `${basename(nbPath)}`,
123+
[kOutputFile]: `${basename(nbPath)}.html`,
125124
[kTemplate]: template,
126125
[kNotebookViewStyle]: kNotebookViewStyleNotebook,
127126
[kAppendixStyle]: "none",

src/render/notebook/notebook-contributor-ipynb.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,6 @@ async function renderOutputNotebook(
7171
_subArticleToken: string,
7272
services: RenderServices,
7373
_notebookMetadata?: NotebookMetadata,
74-
outputFile?: string,
7574
project?: ProjectContext,
7675
): Promise<RenderedFile> {
7776
const rendered = await renderFiles(
@@ -81,7 +80,7 @@ async function renderOutputNotebook(
8180
flags: {
8281
metadata: {
8382
[kTo]: "ipynb",
84-
[kOutputFile]: outputFile || ipynbOutputFile(nbPath),
83+
[kOutputFile]: ipynbOutputFile(nbPath),
8584
},
8685
quiet: false,
8786
},

src/render/notebook/notebook-contributor-jats.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,6 @@ async function renderJats(
7777
subArticleToken: string,
7878
services: RenderServices,
7979
_notebookMetadata?: NotebookMetadata,
80-
outputFile?: string,
8180
project?: ProjectContext,
8281
): Promise<RenderedFile> {
8382
const rendered = await renderFiles(
@@ -90,7 +89,7 @@ async function renderJats(
9089
[kLintXml]: false,
9190
[kJatsSubarticle]: true,
9291
[kJatsSubarticleId]: subArticleToken,
93-
[kOutputFile]: outputFile || jatsOutputFile(nbPath),
92+
[kOutputFile]: jatsOutputFile(nbPath),
9493
[kTemplate]: subarticleTemplatePath,
9594
[kNotebookPreserveCells]: true,
9695
[kNotebookPreserveCells]: true,

src/render/notebook/notebook-types.ts

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,12 @@ export interface NotebookOutput {
4444
resourceFiles: RenderResourceFiles;
4545
}
4646

47+
export interface NotebookRenderResult {
48+
file: string;
49+
supporting?: string[];
50+
resourceFiles: RenderResourceFiles;
51+
}
52+
4753
// Metadata that can be passed when rendering/resolving a notebook
4854
export interface NotebookMetadata {
4955
title: string;
@@ -61,7 +67,7 @@ export interface NotebookTemplateMetadata extends NotebookMetadata {
6167

6268
export interface NotebookContext {
6369
// Retrieves the notebook from the context.
64-
get: (nbPath: string) => Notebook | undefined;
70+
get: (nbPath: string, outputFile?: string) => Notebook | undefined;
6571
// Resolves the data on an executedFile into data that will
6672
// create a `renderType` output when rendered.
6773
resolve: (
@@ -89,7 +95,6 @@ export interface NotebookContext {
8995
renderType: RenderType,
9096
renderServices: RenderServices,
9197
notebookMetadata?: NotebookMetadata,
92-
outputFile?: string,
9398
project?: ProjectContext,
9499
) => Promise<NotebookPreview>;
95100
// Previews are cleaned up when the notebook context is disposed, but
@@ -113,7 +118,6 @@ export interface NotebookContributor {
113118
token: string,
114119
services: RenderServices,
115120
notebookMetadata?: NotebookMetadata,
116-
outputFile?: string,
117121
project?: ProjectContext,
118-
): Promise<RenderedFile>;
122+
): Promise<NotebookRenderResult>;
119123
}

src/resources/filters/layout/manuscript.lua

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,14 +69,18 @@ function manuscript()
6969

7070
-- Provide preview path for the preview generator - this
7171
-- will specify a preview file name to use when generating this preview
72-
-- TODO Should we really just handle this by convention?
72+
--
73+
-- NOTE: This is a point of coordinate where the name of the notebooks is important
74+
-- and this is relying upon that name being present in order to form these links
75+
--
76+
-- TODO: Make the filter params include notebook-context information that
77+
-- can be used to resolve links (if they are present)
7378
local nbFileName = pandoc.path.filename(nbPath)
7479
local nbDir = pandoc.path.directory(nbPath)
7580
if nbDir == "." then
7681
nbDir = ""
7782
end
7883
local previewFile = nbFileName .. ".html"
79-
divEl.attributes['notebook-preview-file'] = previewFile;
8084
local previewPath = pandoc.path.join({nbDir, previewFile})
8185

8286
-- The title for the notebook

0 commit comments

Comments
 (0)