Skip to content

Commit 2dbf319

Browse files
committed
re-use RenderServices properly
1 parent fcdcbf5 commit 2dbf319

File tree

16 files changed

+85
-68
lines changed

16 files changed

+85
-68
lines changed

src/command/render/filters.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -512,8 +512,8 @@ async function quartoFilterParams(
512512

513513
async function extensionShortcodes(options: PandocOptions) {
514514
const extensionShortcodes: string[] = [];
515-
if (options.extension) {
516-
const allExtensions = await options.extension?.extensions(
515+
if (options.services.extension) {
516+
const allExtensions = await options.services.extension?.extensions(
517517
options.source,
518518
options.project?.config,
519519
options.project?.dir,
@@ -681,7 +681,7 @@ async function resolveFilterExtension(
681681
typeof (filter) === "string" &&
682682
!existsSync(filter)
683683
) {
684-
let extensions = await options.extension?.find(
684+
let extensions = await options.services.extension?.find(
685685
filter,
686686
options.source,
687687
"filters",

src/command/render/pandoc.ts

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -317,7 +317,7 @@ export async function runPandoc(
317317
const htmlPostprocessors: Array<HtmlPostProcessor> = [];
318318
const htmlFinalizers: Array<(doc: Document) => Promise<void>> = [];
319319
const htmlRenderAfterBody: string[] = [];
320-
const dependenciesFile = options.temp.createFile();
320+
const dependenciesFile = options.services.temp.createFile();
321321

322322
if (
323323
sysFilters.length > 0 || options.format.formatExtras ||
@@ -329,7 +329,7 @@ export async function runPandoc(
329329
options.source,
330330
options.flags || {},
331331
options.format,
332-
options.temp,
332+
options.services,
333333
))
334334
: {};
335335

@@ -340,9 +340,8 @@ export async function runPandoc(
340340
options.flags || {},
341341
options.format,
342342
options.libDir,
343-
options.temp,
343+
options.services,
344344
options.offset,
345-
options.extension,
346345
options.project,
347346
))
348347
: {};
@@ -353,7 +352,7 @@ export async function runPandoc(
353352
options.format,
354353
cwd,
355354
options.libDir,
356-
options.temp,
355+
options.services.temp,
357356
dependenciesFile,
358357
options.project,
359358
);
@@ -619,7 +618,7 @@ export async function runPandoc(
619618
if (extras.html?.[kBodyEnvelope] && projectExtras.html?.[kBodyEnvelope]) {
620619
extras.html[kBodyEnvelope] = projectExtras.html[kBodyEnvelope];
621620
}
622-
resolveBodyEnvelope(allDefaults, extras, options.temp);
621+
resolveBodyEnvelope(allDefaults, extras, options.services.temp);
623622

624623
// add any filters
625624
allDefaults.filters = [
@@ -694,10 +693,10 @@ export async function runPandoc(
694693
}
695694

696695
// filter results json file
697-
const filterResultsFile = options.temp.createFile();
696+
const filterResultsFile = options.services.temp.createFile();
698697

699698
// timing results json file
700-
const timingResultsFile = options.temp.createFile();
699+
const timingResultsFile = options.services.temp.createFile();
701700

702701
if (allDefaults.to?.match(/[.]lua$/)) {
703702
formatFilterParams["custom-writer"] = allDefaults.to;
@@ -809,7 +808,10 @@ export async function runPandoc(
809808

810809
// write the defaults file
811810
if (allDefaults) {
812-
const defaultsFile = await writeDefaultsFile(allDefaults, options.temp);
811+
const defaultsFile = await writeDefaultsFile(
812+
allDefaults,
813+
options.services.temp,
814+
);
813815
cmd.push("--defaults", defaultsFile);
814816
}
815817

@@ -933,7 +935,7 @@ export async function runPandoc(
933935
keepSourceBlock(options.format, options.source);
934936

935937
// write input to temp file and pass it to pandoc
936-
const inputTemp = options.temp.createFile({
938+
const inputTemp = options.services.temp.createFile({
937939
prefix: "quarto-input",
938940
suffix: ".md",
939941
});
@@ -956,7 +958,7 @@ export async function runPandoc(
956958
// This gives the semantics we want, as our metadata is 'logically' at the top of the
957959
// file and subsequent blocks within the file should indeed override it (as should
958960
// user invocations of --metadata-file or -M, which are included below in pandocArgs)
959-
const metadataTemp = options.temp.createFile({
961+
const metadataTemp = options.services.temp.createFile({
960962
prefix: "quarto-metadata",
961963
suffix: ".yml",
962964
});

src/command/render/render.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -148,9 +148,8 @@ export async function renderPandoc(
148148
format,
149149
project: context.project,
150150
args: recipe.args,
151-
temp: context.options.services.temp,
151+
services: context.options.services,
152152
metadata: executeResult.metadata,
153-
extension: context.options.services.extension,
154153
quiet,
155154
flags: context.options.flags,
156155
};
@@ -437,8 +436,8 @@ async function runHtmlPostprocessors(
437436
{
438437
inputMetadata,
439438
inputTraits,
440-
renderedFormats
441-
}
439+
renderedFormats,
440+
},
442441
);
443442

444443
postProcessResult.resources.push(...result.resources);

src/command/render/template.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ export async function stageTemplate(
6262
extras: FormatExtras,
6363
userContext?: FormatTemplateContext,
6464
) {
65-
const stagingDir = options.temp.createDir();
65+
const stagingDir = options.services.temp.createDir();
6666
const template = "template.patched";
6767

6868
const stageContext = (

src/command/render/types.ts

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -176,18 +176,15 @@ export interface PandocOptions {
176176
// command line args for pandoc
177177
args: string[];
178178

179-
// temp context
180-
temp: TempContext;
179+
// the render services
180+
services: RenderServices;
181181

182182
// extra metadata to merge
183183
metadata?: Metadata;
184184

185185
// optoinal project context
186186
project?: ProjectContext;
187187

188-
// optional extension context
189-
extension?: ExtensionContext;
190-
191188
// quiet quarto pandoc informational output
192189
quiet?: boolean;
193190

src/config/types.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,7 @@ import {
198198
} from "./constants.ts";
199199

200200
import { TempContext } from "../core/temp-types.ts";
201-
import { HtmlPostProcessor } from "../command/render/types.ts";
201+
import { HtmlPostProcessor, RenderServices } from "../command/render/types.ts";
202202
import { QuartoFilterSpec } from "../command/render/filters.ts";
203203
import { ExtensionContext } from "../extension/extension-shared.ts";
204204
import { ProjectContext } from "../project/types.ts";
@@ -357,9 +357,8 @@ export interface Format {
357357
flags: PandocFlags,
358358
format: Format,
359359
libDir: string,
360-
temp: TempContext,
360+
services: RenderServices,
361361
offset?: string,
362-
extensionContext?: ExtensionContext,
363362
project?: ProjectContext,
364363
) => Promise<FormatExtras>;
365364
formatPreviewFile?: (

src/format/html/format-html-bootstrap.ts

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ import {
5959
HtmlPostProcessResult,
6060
PandocInputTraits,
6161
RenderedFormat,
62+
RenderServices,
6263
} from "../../command/render/types.ts";
6364
import { processDocumentAppendix } from "./format-html-appendix.ts";
6465
import {
@@ -124,7 +125,7 @@ export function boostrapExtras(
124125
input: string,
125126
flags: PandocFlags,
126127
format: Format,
127-
temp: TempContext,
128+
services: RenderServices,
128129
offset?: string,
129130
): FormatExtras {
130131
const toc = hasTableOfContents(flags, format);
@@ -175,7 +176,11 @@ export function boostrapExtras(
175176
sassLayers.push(titleSassLayer);
176177
}
177178
const includeInHeader: string[] = [];
178-
const titleInclude = documentTitleIncludeInHeader(input, format, temp);
179+
const titleInclude = documentTitleIncludeInHeader(
180+
input,
181+
format,
182+
services.temp,
183+
);
179184
if (titleInclude) {
180185
includeInHeader.push(titleInclude);
181186
}
@@ -206,6 +211,7 @@ export function boostrapExtras(
206211
input,
207212
format,
208213
flags,
214+
services,
209215
offset,
210216
),
211217
],
@@ -227,6 +233,7 @@ function bootstrapHtmlPostprocessor(
227233
input: string,
228234
format: Format,
229235
flags: PandocFlags,
236+
services: RenderServices,
230237
offset?: string,
231238
): HtmlPostProcessor {
232239
return async (
@@ -327,7 +334,7 @@ function bootstrapHtmlPostprocessor(
327334

328335
// Look for included / embedded notebooks and include those
329336
if (format.render[kNotebookLinks] !== false) {
330-
await processNotebookEmbeds(input, doc, format, resources);
337+
await processNotebookEmbeds(input, doc, format, resources, services);
331338
}
332339

333340
// default treatment for computational tables

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ import {
2626
HtmlPostProcessResult,
2727
RenderServices,
2828
} from "../../command/render/types.ts";
29-
import { render, renderServices } from "../../command/render/render-shared.ts";
29+
import { render } from "../../command/render/render-shared.ts";
3030

3131
import { basename, dirname, join, relative } from "path/mod.ts";
3232

@@ -87,6 +87,7 @@ export async function processNotebookEmbeds(
8787
doc: Document,
8888
format: Format,
8989
resources: string[],
90+
services: RenderServices,
9091
) {
9192
const inline = format.render[kNotebookLinks] === "inline" ||
9293
format.render[kNotebookLinks] === true;
@@ -99,7 +100,6 @@ export async function processNotebookEmbeds(
99100
if (notebookDivNodes.length > 0) {
100101
const nbPaths: { href: string; title: string; filename?: string }[] = [];
101102
let count = 1;
102-
const services = renderServices();
103103

104104
// Emit links to the notebooks inline (where the embedded content is located)
105105
const linkedNotebooks: string[] = [];

src/format/html/format-html.ts

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,10 @@ import {
8383
kSiteUrl,
8484
kWebsite,
8585
} from "../../project/types/website/website-constants.ts";
86-
import { HtmlPostProcessResult } from "../../command/render/types.ts";
86+
import {
87+
HtmlPostProcessResult,
88+
RenderServices,
89+
} from "../../command/render/types.ts";
8790
import {
8891
getDiscussionCategoryId,
8992
getGithubDiscussionsMetadata,
@@ -122,13 +125,13 @@ export function htmlFormat(
122125
flags: PandocFlags,
123126
format: Format,
124127
_libDir: string,
125-
temp: TempContext,
128+
services: RenderServices,
126129
offset: string,
127130
) => {
128131
const htmlFilterParams = htmlFormatFilterParams(format);
129132
return mergeConfigs(
130-
await htmlFormatExtras(input, flags, offset, format, temp),
131-
themeFormatExtras(input, flags, format, temp, offset),
133+
await htmlFormatExtras(input, flags, offset, format, services.temp),
134+
themeFormatExtras(input, flags, format, services, offset),
132135
{ [kFilterParams]: htmlFilterParams },
133136
);
134137
},
@@ -856,7 +859,7 @@ function themeFormatExtras(
856859
input: string,
857860
flags: PandocFlags,
858861
format: Format,
859-
temp: TempContext,
862+
sevices: RenderServices,
860863
offset?: string,
861864
) {
862865
const theme = format.metadata[kTheme];
@@ -869,7 +872,7 @@ function themeFormatExtras(
869872
} else if (theme === "pandoc") {
870873
return pandocExtras(format);
871874
} else {
872-
return boostrapExtras(input, flags, format, temp, offset);
875+
return boostrapExtras(input, flags, format, sevices, offset);
873876
}
874877
}
875878

src/format/jats/format-jats.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,14 @@ import {
1212
kVariant,
1313
} from "../../config/constants.ts";
1414
import { Format, PandocFlags } from "../../config/types.ts";
15-
import { TempContext } from "../../core/temp-types.ts";
16-
import { ExtensionContext } from "../../extension/extension-shared.ts";
1715
import { ProjectContext } from "../../project/types.ts";
1816
import { createFormat } from "../formats-shared.ts";
1917

2018
import { warning } from "log/mod.ts";
2119
import { formatResourcePath } from "../../core/resources.ts";
2220
import { join } from "path/mod.ts";
2321
import { reformat } from "../../core/xml.ts";
22+
import { RenderServices } from "../../command/render/types.ts";
2423

2524
const kJatsExtended = "jats-extended";
2625
const kJatsDtd = "jats-dtd";
@@ -41,9 +40,8 @@ export function jatsFormat(displayName: string, ext: string): Format {
4140
_flags: PandocFlags,
4241
format: Format,
4342
_libDir: string,
44-
_temp: TempContext,
43+
_services: RenderServices,
4544
_offset?: string,
46-
_extensionContext?: ExtensionContext,
4745
_project?: ProjectContext,
4846
) => {
4947
// Provide a template and partials

0 commit comments

Comments
 (0)