Skip to content

Commit 7a9558d

Browse files
cscheidjjallaire
authored andcommitted
use mergeAdditionalFormats to provide custom defaults for cell handlers. Closes #1485
1 parent 5246d7d commit 7a9558d

File tree

4 files changed

+34
-4
lines changed

4 files changed

+34
-4
lines changed

src/command/render/render-contexts.ts

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -499,13 +499,20 @@ async function resolveFormats(
499499
);
500500

501501
// do the merge of the writer format into this format
502-
if (extensionMetadata) {
503-
mergedFormats[format] = mergeFormatMetadata(
502+
mergedFormats[format] = mergeFormatMetadata(
503+
defaultWriterFormat(formatDesc.formatWithVariants),
504+
extensionMetadata[formatDesc.baseFormat],
505+
userFormat,
506+
);
507+
//deno-lint-ignore no-explicit-any
508+
mergedFormats[format].mergeAdditionalFormats = (...configs: any[]) => {
509+
return mergeFormatMetadata(
504510
defaultWriterFormat(formatDesc.formatWithVariants),
505511
extensionMetadata[formatDesc.baseFormat],
512+
...configs,
506513
userFormat,
507514
);
508-
}
515+
};
509516
}
510517

511518
// filter on formats supported by this project

src/config/types.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -291,6 +291,18 @@ export interface Format {
291291
pandoc: FormatPandoc;
292292
language: FormatLanguage;
293293
metadata: Metadata;
294+
295+
/**
296+
* mergeAdditionalFormats is populated by render-contexts, and
297+
* are used to create a Format object with additional formats that
298+
* have "less priority" than format information from user YAML.
299+
*
300+
* Use mergeAdditionalFormats to, e.g., set up custom defaults
301+
* that are not driven by the output format.
302+
*/
303+
//deno-lint-ignore no-explicit-any
304+
mergeAdditionalFormats?: (...configs: any[]) => Format;
305+
294306
resolveFormat?: (format: Format) => void;
295307
formatExtras?: (
296308
input: string,

src/core/handlers/base.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -461,12 +461,22 @@ export const baseHandler: LanguageHandler = {
461461
handlerContext: LanguageCellHandlerContext,
462462
cells: QuartoMdCell[],
463463
): Promise<MappedString[]> {
464+
console.log(handlerContext);
464465
this.documentStart(handlerContext);
466+
const mermaidExecute =
467+
handlerContext.options.format.mergeAdditionalFormats!(
468+
{
469+
execute: this.defaultOptions,
470+
},
471+
).execute;
465472
const result = await Promise.all(cells.map((cell) => {
466473
return this.cell(
467474
handlerContext,
468475
cell,
469-
mergeConfigs(this.defaultOptions ?? {}, cell.options ?? {}),
476+
mergeConfigs(
477+
mermaidExecute as Record<string, unknown>,
478+
cell.options ?? {},
479+
),
470480
);
471481
}));
472482
this.documentEnd(handlerContext);

src/core/handlers/mermaid.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ object:
8181
cell: QuartoMdCell,
8282
options: Record<string, unknown>,
8383
) {
84+
console.log(options);
8485
const cellContent = handlerContext.cellContent(cell);
8586
// TODO escaping removes MappedString information.
8687
// create puppeteer target page

0 commit comments

Comments
 (0)