From 7547a7ed060d427538ea5ebe7b987a9e0e03fb91 Mon Sep 17 00:00:00 2001 From: Carlos Scheidegger Date: Tue, 29 Oct 2024 09:46:21 -0700 Subject: [PATCH 1/3] support inline brand definitions in documents --- src/project/project-shared.ts | 40 ++++++++++--------- src/resources/editor/tools/vs-code.mjs | 19 +++++++-- src/resources/editor/tools/yaml/web-worker.js | 19 +++++++-- .../yaml/yaml-intelligence-resources.json | 19 +++++++-- src/resources/schema/document-options.yml | 7 ++++ 5 files changed, 74 insertions(+), 30 deletions(-) diff --git a/src/project/project-shared.ts b/src/project/project-shared.ts index 689fc8b4bb0..13b28744a93 100644 --- a/src/project/project-shared.ts +++ b/src/project/project-shared.ts @@ -50,6 +50,7 @@ import { refSchema } from "../core/lib/yaml-schema/common.ts"; import { Brand as BrandJson } from "../resources/types/schema-types.ts"; import { Brand } from "../core/brand/brand.ts"; import { warnOnce } from "../core/log.ts"; +import { assert } from "testing/asserts"; export function projectExcludeDirs(context: ProjectContext): string[] { const outputDir = projectOutputDir(context); @@ -556,25 +557,28 @@ export async function projectResolveBrand( if (fileInformation.brand) { return fileInformation.brand; } - if (typeof metadata.brand !== "string") { - warnOnce( - `Brand metadata must be a filename, but is of type ${typeof metadata - .brand} in file ${fileName}. Will ignore brand information`, - ); - return project.resolveBrand(); - } - let brandPath: string = ""; - if (brandPath.startsWith("/")) { - brandPath = join(project.dir, metadata.brand); + if (typeof metadata.brand === "string") { + let brandPath: string = ""; + if (brandPath.startsWith("/")) { + brandPath = join(project.dir, metadata.brand); + } else { + brandPath = join(dirname(fileName), metadata.brand); + } + const brand = await readAndValidateYamlFromFile( + brandPath, + refSchema("brand", "Format-independent brand configuration."), + "Brand validation failed for " + brandPath + ".", + ) as BrandJson; + fileInformation.brand = new Brand(brand, dirname(brandPath), project.dir); + return fileInformation.brand; } else { - brandPath = join(dirname(fileName), metadata.brand); + assert(typeof metadata.brand === "object"); + fileInformation.brand = new Brand( + metadata.brand as BrandJson, + dirname(fileName), + project.dir, + ); + return fileInformation.brand; } - const brand = await readAndValidateYamlFromFile( - brandPath, - refSchema("brand", "Format-independent brand configuration."), - "Brand validation failed for " + brandPath + ".", - ) as BrandJson; - fileInformation.brand = new Brand(brand, dirname(brandPath), project.dir); - return fileInformation.brand; } } diff --git a/src/resources/editor/tools/vs-code.mjs b/src/resources/editor/tools/vs-code.mjs index 5fc88873254..a6eaf99ee68 100644 --- a/src/resources/editor/tools/vs-code.mjs +++ b/src/resources/editor/tools/vs-code.mjs @@ -16628,6 +16628,17 @@ var require_yaml_intelligence_resources = __commonJS({ schema: "path", description: "Use the specified file as a style reference in producing a docx, \npptx, or odt file.\n" }, + { + name: "brand", + schema: { + anyOf: [ + "string", + { + ref: "brand" + } + ] + } + }, { name: "theme", tags: { @@ -22618,7 +22629,7 @@ var require_yaml_intelligence_resources = __commonJS({ "The page layout to use for this document (article,\nfull, or custom)", { short: "Target page width for output (used to compute columns widths for\nlayout divs)", - long: "Target page width for output (used to compute columns widths for\nlayout divs). Defaults to 6.5 inches, which corresponds to\ndefault letter page settings in docx and odt." + long: "Target body page width for output (used to compute columns widths for\nlayout divs). Defaults to 6.5 inches, which corresponds to\ndefault letter page settings in docx and odt (8.5 inches with 1 inch for\neach margins)." }, { short: "Properties of the grid system used to layout Quarto HTML pages.", @@ -24118,12 +24129,12 @@ var require_yaml_intelligence_resources = __commonJS({ mermaid: "%%" }, "handlers/mermaid/schema.yml": { - _internalId: 192600, + _internalId: 192608, type: "object", description: "be an object", properties: { "mermaid-format": { - _internalId: 192592, + _internalId: 192600, type: "enum", enum: [ "png", @@ -24139,7 +24150,7 @@ var require_yaml_intelligence_resources = __commonJS({ exhaustiveCompletions: true }, theme: { - _internalId: 192599, + _internalId: 192607, type: "anyOf", anyOf: [ { diff --git a/src/resources/editor/tools/yaml/web-worker.js b/src/resources/editor/tools/yaml/web-worker.js index cf737422f7a..d2511f0c33c 100644 --- a/src/resources/editor/tools/yaml/web-worker.js +++ b/src/resources/editor/tools/yaml/web-worker.js @@ -16629,6 +16629,17 @@ try { schema: "path", description: "Use the specified file as a style reference in producing a docx, \npptx, or odt file.\n" }, + { + name: "brand", + schema: { + anyOf: [ + "string", + { + ref: "brand" + } + ] + } + }, { name: "theme", tags: { @@ -22619,7 +22630,7 @@ try { "The page layout to use for this document (article,\nfull, or custom)", { short: "Target page width for output (used to compute columns widths for\nlayout divs)", - long: "Target page width for output (used to compute columns widths for\nlayout divs). Defaults to 6.5 inches, which corresponds to\ndefault letter page settings in docx and odt." + long: "Target body page width for output (used to compute columns widths for\nlayout divs). Defaults to 6.5 inches, which corresponds to\ndefault letter page settings in docx and odt (8.5 inches with 1 inch for\neach margins)." }, { short: "Properties of the grid system used to layout Quarto HTML pages.", @@ -24119,12 +24130,12 @@ try { mermaid: "%%" }, "handlers/mermaid/schema.yml": { - _internalId: 192600, + _internalId: 192608, type: "object", description: "be an object", properties: { "mermaid-format": { - _internalId: 192592, + _internalId: 192600, type: "enum", enum: [ "png", @@ -24140,7 +24151,7 @@ try { exhaustiveCompletions: true }, theme: { - _internalId: 192599, + _internalId: 192607, type: "anyOf", anyOf: [ { diff --git a/src/resources/editor/tools/yaml/yaml-intelligence-resources.json b/src/resources/editor/tools/yaml/yaml-intelligence-resources.json index 876a616bd1a..2b87f4f03c7 100644 --- a/src/resources/editor/tools/yaml/yaml-intelligence-resources.json +++ b/src/resources/editor/tools/yaml/yaml-intelligence-resources.json @@ -9600,6 +9600,17 @@ "schema": "path", "description": "Use the specified file as a style reference in producing a docx, \npptx, or odt file.\n" }, + { + "name": "brand", + "schema": { + "anyOf": [ + "string", + { + "ref": "brand" + } + ] + } + }, { "name": "theme", "tags": { @@ -15590,7 +15601,7 @@ "The page layout to use for this document (article,\nfull, or custom)", { "short": "Target page width for output (used to compute columns widths for\nlayout divs)", - "long": "Target page width for output (used to compute columns widths for\nlayout divs). Defaults to 6.5 inches, which corresponds to\ndefault letter page settings in docx and odt." + "long": "Target body page width for output (used to compute columns widths for\nlayout divs). Defaults to 6.5 inches, which corresponds to\ndefault letter page settings in docx and odt (8.5 inches with 1 inch for\neach margins)." }, { "short": "Properties of the grid system used to layout Quarto HTML pages.", @@ -17090,12 +17101,12 @@ "mermaid": "%%" }, "handlers/mermaid/schema.yml": { - "_internalId": 192600, + "_internalId": 192608, "type": "object", "description": "be an object", "properties": { "mermaid-format": { - "_internalId": 192592, + "_internalId": 192600, "type": "enum", "enum": [ "png", @@ -17111,7 +17122,7 @@ "exhaustiveCompletions": true }, "theme": { - "_internalId": 192599, + "_internalId": 192607, "type": "anyOf", "anyOf": [ { diff --git a/src/resources/schema/document-options.yml b/src/resources/schema/document-options.yml index 4fc27aa01b9..87cb8322cb2 100644 --- a/src/resources/schema/document-options.yml +++ b/src/resources/schema/document-options.yml @@ -6,6 +6,13 @@ Use the specified file as a style reference in producing a docx, pptx, or odt file. +- name: brand + schema: + anyOf: + - string # a file path + - boolean # if false, don't use branding on this document + - ref: brand # an inline brand object definition + - name: theme tags: formats: [$html-doc, revealjs, beamer, dashboard] From abe643061d6d0a66c55032f18e0def82ba471945 Mon Sep 17 00:00:00 2001 From: Carlos Scheidegger Date: Tue, 29 Oct 2024 09:46:31 -0700 Subject: [PATCH 2/3] regression test --- .../2024/10/29/feature-11192/.gitignore | 1 + .../2024/10/29/feature-11192/_quarto.yml | 17 +++++++++++++ .../2024/10/29/feature-11192/index.qmd | 24 +++++++++++++++++++ .../2024/10/29/feature-11192/styles.css | 1 + 4 files changed, 43 insertions(+) create mode 100644 tests/docs/smoke-all/2024/10/29/feature-11192/.gitignore create mode 100644 tests/docs/smoke-all/2024/10/29/feature-11192/_quarto.yml create mode 100644 tests/docs/smoke-all/2024/10/29/feature-11192/index.qmd create mode 100644 tests/docs/smoke-all/2024/10/29/feature-11192/styles.css diff --git a/tests/docs/smoke-all/2024/10/29/feature-11192/.gitignore b/tests/docs/smoke-all/2024/10/29/feature-11192/.gitignore new file mode 100644 index 00000000000..075b2542afb --- /dev/null +++ b/tests/docs/smoke-all/2024/10/29/feature-11192/.gitignore @@ -0,0 +1 @@ +/.quarto/ diff --git a/tests/docs/smoke-all/2024/10/29/feature-11192/_quarto.yml b/tests/docs/smoke-all/2024/10/29/feature-11192/_quarto.yml new file mode 100644 index 00000000000..8127758f1e5 --- /dev/null +++ b/tests/docs/smoke-all/2024/10/29/feature-11192/_quarto.yml @@ -0,0 +1,17 @@ +project: + type: website + +website: + title: "feature-11192" + navbar: + left: + - href: index.qmd + text: Home + +format: + html: + css: styles.css + toc: true + + + diff --git a/tests/docs/smoke-all/2024/10/29/feature-11192/index.qmd b/tests/docs/smoke-all/2024/10/29/feature-11192/index.qmd new file mode 100644 index 00000000000..79f9e9c0f5c --- /dev/null +++ b/tests/docs/smoke-all/2024/10/29/feature-11192/index.qmd @@ -0,0 +1,24 @@ +--- +title: "feature-11192" +brand: + color: + palette: + white: '#eeddcc' + black: '#112233' + primary: red + background: black + foreground: white +format: html +_quarto: + tests: + html: + ensureFileRegexMatches: + - ['

#eeddcc

'] + - [] +--- + +{{< brand color white >}} + +This is a Quarto website. + +To learn more about Quarto websites visit . diff --git a/tests/docs/smoke-all/2024/10/29/feature-11192/styles.css b/tests/docs/smoke-all/2024/10/29/feature-11192/styles.css new file mode 100644 index 00000000000..2ddf50c7b42 --- /dev/null +++ b/tests/docs/smoke-all/2024/10/29/feature-11192/styles.css @@ -0,0 +1 @@ +/* css styles */ From 1c5104b60be709665103aa041392efb7092aef61 Mon Sep 17 00:00:00 2001 From: Carlos Scheidegger Date: Tue, 29 Oct 2024 14:26:52 -0700 Subject: [PATCH 3/3] fix schema --- src/resources/editor/tools/vs-code.mjs | 10 ++++++---- src/resources/editor/tools/yaml/web-worker.js | 10 ++++++---- .../editor/tools/yaml/yaml-intelligence-resources.json | 10 ++++++---- src/resources/schema/document-options.yml | 4 ++++ 4 files changed, 22 insertions(+), 12 deletions(-) diff --git a/src/resources/editor/tools/vs-code.mjs b/src/resources/editor/tools/vs-code.mjs index a6eaf99ee68..0dabfc757d9 100644 --- a/src/resources/editor/tools/vs-code.mjs +++ b/src/resources/editor/tools/vs-code.mjs @@ -16633,11 +16633,13 @@ var require_yaml_intelligence_resources = __commonJS({ schema: { anyOf: [ "string", + "boolean", { ref: "brand" } ] - } + }, + description: "Branding information to use for this document. If a string, the path to a brand file.\nIf false, don't use branding on this document. If an object, an inline brand\ndefinition.\n" }, { name: "theme", @@ -24129,12 +24131,12 @@ var require_yaml_intelligence_resources = __commonJS({ mermaid: "%%" }, "handlers/mermaid/schema.yml": { - _internalId: 192608, + _internalId: 193258, type: "object", description: "be an object", properties: { "mermaid-format": { - _internalId: 192600, + _internalId: 193250, type: "enum", enum: [ "png", @@ -24150,7 +24152,7 @@ var require_yaml_intelligence_resources = __commonJS({ exhaustiveCompletions: true }, theme: { - _internalId: 192607, + _internalId: 193257, type: "anyOf", anyOf: [ { diff --git a/src/resources/editor/tools/yaml/web-worker.js b/src/resources/editor/tools/yaml/web-worker.js index d2511f0c33c..f962e83385a 100644 --- a/src/resources/editor/tools/yaml/web-worker.js +++ b/src/resources/editor/tools/yaml/web-worker.js @@ -16634,11 +16634,13 @@ try { schema: { anyOf: [ "string", + "boolean", { ref: "brand" } ] - } + }, + description: "Branding information to use for this document. If a string, the path to a brand file.\nIf false, don't use branding on this document. If an object, an inline brand\ndefinition.\n" }, { name: "theme", @@ -24130,12 +24132,12 @@ try { mermaid: "%%" }, "handlers/mermaid/schema.yml": { - _internalId: 192608, + _internalId: 193258, type: "object", description: "be an object", properties: { "mermaid-format": { - _internalId: 192600, + _internalId: 193250, type: "enum", enum: [ "png", @@ -24151,7 +24153,7 @@ try { exhaustiveCompletions: true }, theme: { - _internalId: 192607, + _internalId: 193257, type: "anyOf", anyOf: [ { diff --git a/src/resources/editor/tools/yaml/yaml-intelligence-resources.json b/src/resources/editor/tools/yaml/yaml-intelligence-resources.json index 2b87f4f03c7..d523a06de87 100644 --- a/src/resources/editor/tools/yaml/yaml-intelligence-resources.json +++ b/src/resources/editor/tools/yaml/yaml-intelligence-resources.json @@ -9605,11 +9605,13 @@ "schema": { "anyOf": [ "string", + "boolean", { "ref": "brand" } ] - } + }, + "description": "Branding information to use for this document. If a string, the path to a brand file.\nIf false, don't use branding on this document. If an object, an inline brand\ndefinition.\n" }, { "name": "theme", @@ -17101,12 +17103,12 @@ "mermaid": "%%" }, "handlers/mermaid/schema.yml": { - "_internalId": 192608, + "_internalId": 193258, "type": "object", "description": "be an object", "properties": { "mermaid-format": { - "_internalId": 192600, + "_internalId": 193250, "type": "enum", "enum": [ "png", @@ -17122,7 +17124,7 @@ "exhaustiveCompletions": true }, "theme": { - "_internalId": 192607, + "_internalId": 193257, "type": "anyOf", "anyOf": [ { diff --git a/src/resources/schema/document-options.yml b/src/resources/schema/document-options.yml index 87cb8322cb2..1407ceb29e9 100644 --- a/src/resources/schema/document-options.yml +++ b/src/resources/schema/document-options.yml @@ -12,6 +12,10 @@ - string # a file path - boolean # if false, don't use branding on this document - ref: brand # an inline brand object definition + description: | + Branding information to use for this document. If a string, the path to a brand file. + If false, don't use branding on this document. If an object, an inline brand + definition. - name: theme tags: