From f27ceae76c8222e953b7b4508d368d9fd11c539b Mon Sep 17 00:00:00 2001 From: Christophe Dervieux Date: Fri, 4 Apr 2025 12:29:03 +0200 Subject: [PATCH 1/3] don't loose DOCTYPE header in embed resource processing --- src/core/pandoc/self-contained.ts | 4 ++++ .../formats/html/pandoc-selfcontained/selfcontained.html | 1 + 2 files changed, 5 insertions(+) diff --git a/src/core/pandoc/self-contained.ts b/src/core/pandoc/self-contained.ts index ca3e9f55aee..58337886cb3 100644 --- a/src/core/pandoc/self-contained.ts +++ b/src/core/pandoc/self-contained.ts @@ -48,6 +48,7 @@ export const pandocIngestSelfContainedContent = async ( // The raw html contents const contents = Deno.readTextFileSync(file); + const doctypeMatch = contents.match(/^/); const dom = await parseHtml(contents); await bundleModules(dom, workingDir); @@ -63,6 +64,9 @@ export const pandocIngestSelfContainedContent = async ( cmd.push("--template", template); cmd.push("--output", filename); cmd.push("--metadata", "title=placeholder"); + if (doctypeMatch) { + cmd.push("--variable", `doctype=${doctypeMatch[0]}`); + } cmd.push("--embed-resources"); if (resourcePath && resourcePath.length) { cmd.push("--resource-path", resourcePath.join(":")); diff --git a/src/resources/formats/html/pandoc-selfcontained/selfcontained.html b/src/resources/formats/html/pandoc-selfcontained/selfcontained.html index f37d7c6dce5..b835db8363c 100644 --- a/src/resources/formats/html/pandoc-selfcontained/selfcontained.html +++ b/src/resources/formats/html/pandoc-selfcontained/selfcontained.html @@ -1 +1,2 @@ +$if(doctype)$$doctype$$endif$ $body$ \ No newline at end of file From 32550eea455fa9f899f98513f65ee88af27f3f69 Mon Sep 17 00:00:00 2001 From: Christophe Dervieux Date: Fri, 4 Apr 2025 12:36:58 +0200 Subject: [PATCH 2/3] Add a regression test for DOCTYPE presence --- tests/docs/smoke-all/2025/04/04/12295.qmd | 28 +++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 tests/docs/smoke-all/2025/04/04/12295.qmd diff --git a/tests/docs/smoke-all/2025/04/04/12295.qmd b/tests/docs/smoke-all/2025/04/04/12295.qmd new file mode 100644 index 00000000000..13a9eff71dc --- /dev/null +++ b/tests/docs/smoke-all/2025/04/04/12295.qmd @@ -0,0 +1,28 @@ +--- +title: DOCTYPE is not lost when using embed-resources +embed-resources: true +_quarto: + tests: + html: + ensureHtmlElements: + - [] + - [] + ensureFileRegexMatches: + - ['\<\!DOCTYPE html\>'] + - [] + revealjs: + ensureHtmlElements: + - [] + - [] + ensureFileRegexMatches: + - ['\<\!DOCTYPE html\>'] + - [] +--- + +Example from https://github.com/quarto-dev/quarto-cli/issues/12295: Not having DOCTYPE lead to browser using a Quirk mode for CSS, and not applying the standard HTML5. + +## Header + +```bash +quarto render --help +``` \ No newline at end of file From caae7f2d10897eb1769f3c781e53290f0a19e01b Mon Sep 17 00:00:00 2001 From: Christophe Dervieux Date: Fri, 4 Apr 2025 12:56:31 +0200 Subject: [PATCH 3/3] don't use Pandoc variable to avoid problem for complex DOCTYPE --- src/core/pandoc/self-contained.ts | 6 +++--- .../formats/html/pandoc-selfcontained/selfcontained.html | 1 - 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/src/core/pandoc/self-contained.ts b/src/core/pandoc/self-contained.ts index 58337886cb3..252f7181466 100644 --- a/src/core/pandoc/self-contained.ts +++ b/src/core/pandoc/self-contained.ts @@ -54,6 +54,9 @@ export const pandocIngestSelfContainedContent = async ( const input: string[] = []; input.push("````````{=html}"); + if (doctypeMatch) { + input.push(doctypeMatch[0]); + } input.push(dom.documentElement!.outerHTML); input.push("````````"); @@ -64,9 +67,6 @@ export const pandocIngestSelfContainedContent = async ( cmd.push("--template", template); cmd.push("--output", filename); cmd.push("--metadata", "title=placeholder"); - if (doctypeMatch) { - cmd.push("--variable", `doctype=${doctypeMatch[0]}`); - } cmd.push("--embed-resources"); if (resourcePath && resourcePath.length) { cmd.push("--resource-path", resourcePath.join(":")); diff --git a/src/resources/formats/html/pandoc-selfcontained/selfcontained.html b/src/resources/formats/html/pandoc-selfcontained/selfcontained.html index b835db8363c..f37d7c6dce5 100644 --- a/src/resources/formats/html/pandoc-selfcontained/selfcontained.html +++ b/src/resources/formats/html/pandoc-selfcontained/selfcontained.html @@ -1,2 +1 @@ -$if(doctype)$$doctype$$endif$ $body$ \ No newline at end of file