From c45f38d5b307f3de1437d1b3938f853325690750 Mon Sep 17 00:00:00 2001 From: Carlos Scheidegger Date: Mon, 21 Oct 2024 15:42:30 -0700 Subject: [PATCH 1/3] merge metadata instead of overwriting it --- src/command/render/pandoc.ts | 37 ++++++++++++++++++++---------------- 1 file changed, 21 insertions(+), 16 deletions(-) diff --git a/src/command/render/pandoc.ts b/src/command/render/pandoc.ts index c5a69079ef5..42d0d17aa37 100644 --- a/src/command/render/pandoc.ts +++ b/src/command/render/pandoc.ts @@ -201,6 +201,7 @@ import { MarkdownPipelineHandler, } from "../../core/markdown-pipeline.ts"; import { getEnv } from "../../../package/src/util/utils.ts"; +import { is } from "https://cdn.skypack.dev/-/css-select@v5.1.0-lzo7kuDagEAqaWVyUzkG/dist=es2019,mode=imports/optimized/css-select.js"; // in case we are running multiple pandoc processes // we need to make sure we capture all of the trace files @@ -993,25 +994,29 @@ export async function runPandoc( const pandocMetadata = ld.cloneDeep(options.format.metadata || {}); for (const key of Object.keys(engineMetadata)) { const isChapterTitle = key === kTitle && projectIsBook(options.project); + // if it's standard pandoc metadata and NOT contained in a format specific + // override then use the engine metadata value + if (isQuartoMetadata(key) || isChapterTitle || isIncludeMetadata(key)) { + continue; + } - if (!isQuartoMetadata(key) && !isChapterTitle && !isIncludeMetadata(key)) { - // if it's standard pandoc metadata and NOT contained in a format specific - // override then use the engine metadata value - - // don't do if they've overridden the value in a format - const formats = engineMetadata[kMetadataFormat] as Metadata; - if (ld.isObject(formats) && metadataGetDeep(formats, key).length > 0) { - continue; - } + // don't do if they've overridden the value in a format + const formats = engineMetadata[kMetadataFormat] as Metadata; + if (ld.isObject(formats) && metadataGetDeep(formats, key).length > 0) { + continue; + } - // don't process some format specific metadata that may have been processed already - // - theme is handled specifically already for revealjs with a metadata override and should not be overridden by user input - if (key === kTheme && isRevealjsOutput(options.format.pandoc)) { - continue; - } - // perform the override - pandocMetadata[key] = engineMetadata[key]; + // don't process some format specific metadata that may have been processed already + // - theme is handled specifically already for revealjs with a metadata override and should not be overridden by user input + if (key === kTheme && isRevealjsOutput(options.format.pandoc)) { + continue; } + + // perform the override + pandocMetadata[key] = mergeConfigs( + pandocMetadata[key], + engineMetadata[key], + ); } // Resolve any date fields From cd2b48772e3c4f297d3bf4d3bf345673d3f857b6 Mon Sep 17 00:00:00 2001 From: Carlos Scheidegger Date: Mon, 21 Oct 2024 15:49:57 -0700 Subject: [PATCH 2/3] regression test --- .../2024/10/21/issue-11138/.gitignore | 1 + .../2024/10/21/issue-11138/.luarc.json | 22 +++++++++++++++++++ .../2024/10/21/issue-11138/_quarto.yml | 20 +++++++++++++++++ .../2024/10/21/issue-11138/about.qmd | 5 +++++ .../2024/10/21/issue-11138/index.qmd | 11 ++++++++++ .../2024/10/21/issue-11138/styles.css | 1 + .../smoke-all/2024/10/21/issue-11138/test.lua | 8 +++++++ 7 files changed, 68 insertions(+) create mode 100644 tests/docs/smoke-all/2024/10/21/issue-11138/.gitignore create mode 100644 tests/docs/smoke-all/2024/10/21/issue-11138/.luarc.json create mode 100644 tests/docs/smoke-all/2024/10/21/issue-11138/_quarto.yml create mode 100644 tests/docs/smoke-all/2024/10/21/issue-11138/about.qmd create mode 100644 tests/docs/smoke-all/2024/10/21/issue-11138/index.qmd create mode 100644 tests/docs/smoke-all/2024/10/21/issue-11138/styles.css create mode 100644 tests/docs/smoke-all/2024/10/21/issue-11138/test.lua diff --git a/tests/docs/smoke-all/2024/10/21/issue-11138/.gitignore b/tests/docs/smoke-all/2024/10/21/issue-11138/.gitignore new file mode 100644 index 00000000000..075b2542afb --- /dev/null +++ b/tests/docs/smoke-all/2024/10/21/issue-11138/.gitignore @@ -0,0 +1 @@ +/.quarto/ diff --git a/tests/docs/smoke-all/2024/10/21/issue-11138/.luarc.json b/tests/docs/smoke-all/2024/10/21/issue-11138/.luarc.json new file mode 100644 index 00000000000..22a58a3904e --- /dev/null +++ b/tests/docs/smoke-all/2024/10/21/issue-11138/.luarc.json @@ -0,0 +1,22 @@ +{ + "Generator": [ + "Quarto", + "This file provides type information for Lua completion and diagnostics.", + "Quarto will automatically update this file to reflect the current path", + "of your Quarto installation, and the file will also be added to .gitignore", + "since it points to the absolute path of Quarto on the local system.", + "Remove the 'Generator' key to manage this file's contents manually." + ], + "Lua.runtime.version": "Lua 5.3", + "Lua.workspace.checkThirdParty": false, + "Lua.workspace.library": [ + "/Users/cscheid/repos/github/quarto-dev/quarto-cli/src/resources/lua-types" + ], + "Lua.runtime.plugin": "/Users/cscheid/repos/github/quarto-dev/quarto-cli/src/resources/lua-plugin/plugin.lua", + "Lua.completion.showWord": "Disable", + "Lua.completion.keywordSnippet": "Both", + "Lua.diagnostics.disable": [ + "lowercase-global", + "trailing-space" + ] +} \ No newline at end of file diff --git a/tests/docs/smoke-all/2024/10/21/issue-11138/_quarto.yml b/tests/docs/smoke-all/2024/10/21/issue-11138/_quarto.yml new file mode 100644 index 00000000000..49a5f514642 --- /dev/null +++ b/tests/docs/smoke-all/2024/10/21/issue-11138/_quarto.yml @@ -0,0 +1,20 @@ +project: + type: website + +website: + title: "This is the website title" + navbar: + left: + - href: index.qmd + text: Home + - about.qmd + +format: + html: + theme: cosmo + css: styles.css + toc: true + +mymeta: + key1: value1 + key2: value2 diff --git a/tests/docs/smoke-all/2024/10/21/issue-11138/about.qmd b/tests/docs/smoke-all/2024/10/21/issue-11138/about.qmd new file mode 100644 index 00000000000..07c5e7f9d13 --- /dev/null +++ b/tests/docs/smoke-all/2024/10/21/issue-11138/about.qmd @@ -0,0 +1,5 @@ +--- +title: "About" +--- + +About this site diff --git a/tests/docs/smoke-all/2024/10/21/issue-11138/index.qmd b/tests/docs/smoke-all/2024/10/21/issue-11138/index.qmd new file mode 100644 index 00000000000..9fc0cd0991d --- /dev/null +++ b/tests/docs/smoke-all/2024/10/21/issue-11138/index.qmd @@ -0,0 +1,11 @@ +--- +title: "This is the page title" +filters: + - test.lua +mymeta: + key1: override +--- + +This is a Quarto website. + +To learn more about Quarto websites visit . diff --git a/tests/docs/smoke-all/2024/10/21/issue-11138/styles.css b/tests/docs/smoke-all/2024/10/21/issue-11138/styles.css new file mode 100644 index 00000000000..2ddf50c7b42 --- /dev/null +++ b/tests/docs/smoke-all/2024/10/21/issue-11138/styles.css @@ -0,0 +1 @@ +/* css styles */ diff --git a/tests/docs/smoke-all/2024/10/21/issue-11138/test.lua b/tests/docs/smoke-all/2024/10/21/issue-11138/test.lua new file mode 100644 index 00000000000..2fa12231ab9 --- /dev/null +++ b/tests/docs/smoke-all/2024/10/21/issue-11138/test.lua @@ -0,0 +1,8 @@ +function Meta(m) + if pandoc.utils.stringify(m.mymeta.key1) ~= "override" then + crash() + end + if pandoc.utils.stringify(m.mymeta.key2) ~= "value2" then + crash() + end +end \ No newline at end of file From 6d83a40dcab8e7c6565bff049866c19374ff2ea6 Mon Sep 17 00:00:00 2001 From: Carlos Scheidegger Date: Mon, 21 Oct 2024 16:45:24 -0700 Subject: [PATCH 3/3] attempt to start fixing mergeConfigs --- src/core/config.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/core/config.ts b/src/core/config.ts index 27515ecab74..a5129826f35 100644 --- a/src/core/config.ts +++ b/src/core/config.ts @@ -8,14 +8,14 @@ import * as ld from "./lodash.ts"; export function mergeConfigs(config: T, ...configs: Array): T { // copy all configs so we don't mutate them - config = ld.cloneDeep(config); - configs = ld.cloneDeep(configs); + config = ld.cloneDeep({ foo: config }); + configs = ld.cloneDeep(configs.map((x) => ({ foo: x }))); return ld.mergeWith( config, ...configs, mergeArrayCustomizer, - ); + ).foo; } export function mergeArrayCustomizer(objValue: unknown, srcValue: unknown) {