Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions src/command/render/defaults.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,12 @@ export async function generateDefaults(
let allDefaults: FormatPandoc | undefined;

if (options.format.pandoc) {
allDefaults = (options.format.pandoc
? ld.cloneDeep(options.format.pandoc)
: {}) as FormatPandoc;
allDefaults = {
...(options.format.pandoc || {}),
variables: {
...(options.format.pandoc?.variables || {}),
},
} as FormatPandoc;

// resolve filters
const resolvedFilters = await resolveFilters(
Expand Down
1 change: 1 addition & 0 deletions src/command/render/filters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -713,6 +713,7 @@ function initFilterParams(dependenciesFile: string) {
const kQuartoFilterMarker = "quarto";
const kQuartoCiteProcMarker = "citeproc";

// NB: this mutates `pandoc.citeproc`
export async function resolveFilters(
filters: QuartoFilter[],
options: PandocOptions,
Expand Down
9 changes: 6 additions & 3 deletions src/command/render/flags.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,6 @@ import {
import { isQuartoMetadata } from "../../config/metadata.ts";
import { RenderFlags, RenderOptions } from "./types.ts";

import * as ld from "../../core/lodash.ts";

import { isAbsolute, SEP_PATTERN } from "../../deno_ral/path.ts";
import { normalizePath } from "../../core/path.ts";
import { removeFlags } from "../../core/flags.ts";
Expand Down Expand Up @@ -471,7 +469,12 @@ export function removePandocToArg(args: string[]) {
}

export function removePandocTo(renderOptions: RenderOptions) {
renderOptions = ld.cloneDeep(renderOptions);
renderOptions = {
...renderOptions,
flags: {
...(renderOptions.flags || {}),
},
} as RenderOptions;
delete renderOptions.flags?.to;
if (renderOptions.pandocArgs) {
renderOptions.pandocArgs = removePandocToArg(renderOptions.pandocArgs);
Expand Down
16 changes: 8 additions & 8 deletions src/command/render/freeze.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@ import {
LF,
} from "../../deno_ral/fs.ts";

import { cloneDeep } from "../../core/lodash.ts";

import { inputFilesDir } from "../../core/render.ts";
import { TempContext } from "../../core/temp.ts";
import { md5HashSync } from "../../core/hash.ts";
Expand Down Expand Up @@ -55,13 +53,15 @@ export function freezeExecuteResult(
result: ExecuteResult,
) {
// resolve includes within executeResult
result = cloneDeep(result) as ExecuteResult;
const innerResult = {
...result,
} as ExecuteResult;
const resolveIncludes = (
name: "include-in-header" | "include-before-body" | "include-after-body",
) => {
if (result.includes) {
if (result.includes[name]) {
result.includes[name] = result.includes[name]!.map((file) =>
if (innerResult.includes) {
if (innerResult.includes[name]) {
innerResult.includes[name] = innerResult.includes[name]!.map((file) =>
// Storing file content using LF line ending
format(Deno.readTextFileSync(file), LF)
);
Expand All @@ -73,7 +73,7 @@ export function freezeExecuteResult(
resolveIncludes(kIncludeAfterBody);

// make the supporting dirs relative to the input file dir
result.supporting = result.supporting.map((file) => {
innerResult.supporting = innerResult.supporting.map((file) => {
if (isAbsolute(file)) {
return relative(normalizePath(dirname(input)), file);
} else {
Expand All @@ -88,7 +88,7 @@ export function freezeExecuteResult(
const freezeJsonFile = freezeResultFile(input, output, true);
Deno.writeTextFileSync(
freezeJsonFile,
JSON.stringify({ hash, result }, undefined, 2),
JSON.stringify({ hash, result: innerResult }, undefined, 2),
);

// return the file
Expand Down
27 changes: 17 additions & 10 deletions src/command/render/pandoc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -391,9 +391,12 @@ export async function runPandoc(
// save args and metadata so we can print them (we may subsequently edit them)
const printArgs = [...args];
let printMetadata = {
...ld.cloneDeep(options.format.metadata),
...options.format.metadata,
crossref: {
...(options.format.metadata.crossref || {}),
},
...options.flags?.metadata,
};
} as Metadata;

// remove some metadata that are used as parameters to our lua filters
const cleanMetadataForPrinting = (metadata: Metadata) => {
Expand Down Expand Up @@ -691,7 +694,7 @@ export async function runPandoc(
),
...extras.metadataOverride || {},
};
printMetadata = mergeConfigs(extras.metadata, printMetadata);
printMetadata = mergeConfigs(extras.metadata || {}, printMetadata);
cleanMetadataForPrinting(printMetadata);
}

Expand Down Expand Up @@ -820,7 +823,9 @@ export async function runPandoc(
}

// more cleanup
options.format.metadata = cleanupPandocMetadata(options.format.metadata);
options.format.metadata = cleanupPandocMetadata({
...options.format.metadata,
});
printMetadata = cleanupPandocMetadata(printMetadata);

if (extras[kIncludeInHeader]) {
Expand Down Expand Up @@ -1370,21 +1375,20 @@ export async function runPandoc(
}
}

// this mutates metadata[kClassOption]
function cleanupPandocMetadata(metadata: Metadata) {
const cleaned = ld.cloneDeep(metadata);

// pdf classoption can end up with duplicaed options
const classoption = cleaned[kClassOption];
const classoption = metadata[kClassOption];
if (Array.isArray(classoption)) {
cleaned[kClassOption] = ld.uniqBy(
metadata[kClassOption] = ld.uniqBy(
classoption.reverse(),
(option: string) => {
return option.replace(/=.+$/, "");
},
).reverse();
}

return cleaned;
return metadata;
}

async function resolveExtras(
Expand Down Expand Up @@ -1687,7 +1691,10 @@ function resolveTextHighlightStyle(
extras: FormatExtras,
pandoc: FormatPandoc,
): FormatExtras {
extras = ld.cloneDeep(extras);
extras = {
...extras,
pandoc: extras.pandoc ? { ...extras.pandoc } : {},
} as FormatExtras;

// Get the user selected theme or choose a default
const highlightTheme = pandoc[kHighlightStyle] || kDefaultHighlightStyle;
Expand Down
2 changes: 1 addition & 1 deletion src/command/render/project.ts
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ const computeProjectRenderConfig = async (

// force execution for any incremental files (unless options.useFreezer is set)
let alwaysExecuteFiles = incremental && !inputs.options.useFreezer
? ld.cloneDeep(inputs.files) as string[]
? [...(inputs.files!)]
: undefined;

// file normaliation
Expand Down
9 changes: 7 additions & 2 deletions src/core/jupyter/display-data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -123,8 +123,13 @@ export function displayDataWithMarkdownMath(output: JupyterOutputDisplayData) {
if (Array.isArray(output.data[kTextLatex]) && !output.data[kTextMarkdown]) {
const latex = output.data[kTextLatex] as string[];
if (displayDataLatexIsMath(latex)) {
output = ld.cloneDeep(output);
output.data[kTextMarkdown] = output.data[kTextLatex];
output = {
...output,
data: {
...output.data,
[kTextMarkdown]: latex,
},
};
return output;
}
}
Expand Down
8 changes: 6 additions & 2 deletions src/core/jupyter/jupyter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -963,7 +963,9 @@ export function mdFromContentCell(
const contentCellEnvelope = createCellEnvelope(["cell", "markdown"], options);

// clone source for manipulation
const source = ld.cloneDeep(cell.source) as string[];
const source = typeof cell.source === "string"
? [cell.source]
: [...cell.source];

// handle user expressions (if any)
if (options && source) {
Expand Down Expand Up @@ -1461,7 +1463,9 @@ async function mdFromCodeCell(
}
}
md.push("}\n");
let source = ld.cloneDeep(cell.source);
let source = typeof cell.source === "string"
? [cell.source]
: [...cell.source];
if (fenced) {
const optionsSource = cell.optionsSource.filter((line) =>
line.search(/\|\s+echo:\s+fenced\s*$/) === -1
Expand Down
10 changes: 9 additions & 1 deletion src/execute/jupyter/jupyter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,15 @@ export const jupyterEngine: ExecutionEngine = {
isServerShinyPython(format, kJupyterEngine) &&
format.render[kKeepHidden] !== true
) {
format = ld.cloneDeep(format);
format = {
...format,
render: {
...format.render,
},
metadata: {
...format.metadata,
},
};
format.render[kKeepHidden] = true;
format.metadata[kRemoveHidden] = "all";
}
Expand Down
4 changes: 3 additions & 1 deletion src/execute/ojs/compile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -892,7 +892,9 @@ export async function ojsExecuteResult(
executeResult: MappedExecuteResult,
ojsBlockLineNumbers: number[],
) {
executeResult = ld.cloneDeep(executeResult);
executeResult = {
...executeResult,
};

// evaluate ojs chunks
const { markdown, includes, filters, resourceFiles } = await ojsCompile({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,9 @@ export function reshapeListing(
listing: Listing,
format: Format,
): ReshapedListing {
const reshaped = cloneDeep(listing) as Listing;
const reshaped = {
...listing,
} as Listing;

// Add template utilities
const utilities = {} as Record<string, unknown>;
Expand Down
6 changes: 3 additions & 3 deletions src/publish/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@ import { warning } from "../deno_ral/log.ts";
import { stringify } from "../core/yaml.ts";
import { basename, dirname, join } from "../deno_ral/path.ts";

import * as ld from "../core/lodash.ts";

import { Metadata } from "../config/types.ts";
import { readYaml, readYamlFromString } from "../core/yaml.ts";
import { ProjectContext } from "../project/types.ts";
Expand Down Expand Up @@ -69,7 +67,9 @@ export function writePublishDeployment(
publish: PublishRecord,
) {
// don't write 'code' field if false
publish = ld.cloneDeep(publish) as PublishRecord;
publish = {
...publish,
} as PublishRecord;
if (publish.code === false) {
delete (publish as Record<string, unknown>).code;
}
Expand Down
Loading