From 67044dd72aa4635b63f4f74d54de93e133f4d54f Mon Sep 17 00:00:00 2001 From: Christophe Dervieux Date: Thu, 25 Apr 2024 17:25:14 -0400 Subject: [PATCH 1/3] Parsed table wrapping div needs to be scaffold so that it is removed Especially because powerpoint does not allow Div and Tables in Div --- src/resources/filters/normalize/parsehtml.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/resources/filters/normalize/parsehtml.lua b/src/resources/filters/normalize/parsehtml.lua index 1c9007cdbec..3093d2e666f 100644 --- a/src/resources/filters/normalize/parsehtml.lua +++ b/src/resources/filters/normalize/parsehtml.lua @@ -158,7 +158,7 @@ function parse_html_tables() if cursor > 1 and cursor <= len then blocks:insert(pandoc.RawBlock(el.format, string.sub(el.text, cursor))) end - return pandoc.Div(blocks) + return _quarto.ast.scaffold_element(blocks) end local filter From c32f53912cdcec52b1631fa5a1be7ad66c4de17b Mon Sep 17 00:00:00 2001 From: Christophe Dervieux Date: Fri, 26 Apr 2024 09:06:01 -0400 Subject: [PATCH 2/3] Add a test for powerpoint using XPATH --- tests/docs/smoke-all/2024/04/26/9365.qmd | 35 +++++++++ tests/smoke/smoke-all.test.ts | 2 + tests/verify.ts | 92 +++++++++++++++++++----- 3 files changed, 110 insertions(+), 19 deletions(-) create mode 100644 tests/docs/smoke-all/2024/04/26/9365.qmd diff --git a/tests/docs/smoke-all/2024/04/26/9365.qmd b/tests/docs/smoke-all/2024/04/26/9365.qmd new file mode 100644 index 00000000000..3057a45f79f --- /dev/null +++ b/tests/docs/smoke-all/2024/04/26/9365.qmd @@ -0,0 +1,35 @@ +--- +title: Parsed HTML table in PPTX +format: pptx +_quarto: + tests: + pptx: + ensurePptxXpath: + - 2 + - ['//a:tbl'] + - [] +--- + +# Test table + +```{=html} + + + + + + + + + + + + + + + + + +
Sepal.LengthSepal.Width
5.13.5
4.93.0
+``` + diff --git a/tests/smoke/smoke-all.test.ts b/tests/smoke/smoke-all.test.ts index 5eb9b5c73e3..1ac6397dd0d 100644 --- a/tests/smoke/smoke-all.test.ts +++ b/tests/smoke/smoke-all.test.ts @@ -28,6 +28,7 @@ import { fileExists, noErrors, noErrorsOrWarnings, + ensurePptxXpath, } from "../verify.ts"; import { readYaml, readYamlFromMarkdown } from "../../src/core/yaml.ts"; import { outputForInput } from "../utils.ts"; @@ -98,6 +99,7 @@ function resolveTestSpecs( ensureOdtXpath, ensureJatsXpath, ensurePptxRegexMatches, + ensurePptxXpath, ensureSnapshotMatches }; diff --git a/tests/verify.ts b/tests/verify.ts index 7b873db0087..209b62dd231 100644 --- a/tests/verify.ts +++ b/tests/verify.ts @@ -22,25 +22,55 @@ import { isWindows } from "../src/core/platform.ts"; import { execProcess } from "../src/core/process.ts"; import { canonicalizeSnapshot, checkSnapshot } from "./verify-snapshot.ts"; -export const withDocxContent = async (file: string, - k: (xml: string) => Promise) => { - const [_dir, stem] = dirAndStem(file); - const temp = await Deno.makeTempDir(); - try { - // Move the docx to a temp dir and unzip it - const zipFile = join(temp, stem + ".zip"); - await Deno.copyFile(file, zipFile); - await unzip(zipFile); - - // Open the core xml document and match the matches - const docXml = join(temp, "word", "document.xml"); - const xml = await Deno.readTextFile(docXml); - const result = await k(xml); - return result; - } finally { - await Deno.remove(temp, { recursive: true }); - } - }; +export const withDocxContent = async ( + file: string, + k: (xml: string) => Promise +) => { + const [_dir, stem] = dirAndStem(file); + const temp = await Deno.makeTempDir(); + try { + // Move the docx to a temp dir and unzip it + const zipFile = join(temp, stem + ".zip"); + await Deno.copyFile(file, zipFile); + await unzip(zipFile); + + // Open the core xml document and match the matches + const docXml = join(temp, "word", "document.xml"); + const xml = await Deno.readTextFile(docXml); + const result = await k(xml); + return result; + } finally { + await Deno.remove(temp, { recursive: true }); + } +}; + +export const withPptxContent = async ( + file: string, + slideNumber: number, + k: (xml: string) => Promise +) => { + const [_dir, stem] = dirAndStem(file); + const temp = await Deno.makeTempDir(); + try { + // Move the pptx to a temp dir and unzip it + const zipFile = join(temp, stem + ".zip"); + await Deno.copyFile(file, zipFile); + await unzip(zipFile); + + // Open the core xml document and match the matches + const slidePath = join(temp, "ppt", "slides"); + const slideFile = join(slidePath, `slide${slideNumber}.xml`); + assert( + existsSync(slideFile), + `Slide number ${slideNumber} is not in the Pptx`, + ); + const xml = await Deno.readTextFile(slideFile); + const result = await k(xml); + return result; + } finally { + await Deno.remove(temp, { recursive: true }); + } +}; export const noErrors: Verify = { name: "No Errors", @@ -432,6 +462,18 @@ export const verifyDocXDocument = ( }); }; +export const verifyPptxDocument = ( + callback: (doc: string) => Promise, + name?: string, +): (file: string, slideNumber: number) => Verify => { + return (file: string, slideNumber: number) => ({ + name: name ?? "Inspecting Pptx", + verify: async (_output: ExecuteOutput[]) => { + return await withPptxContent(file, slideNumber, callback); + }, + }); +}; + const xmlChecker = ( selectors: string[], noMatchSelectors?: string[], @@ -493,6 +535,18 @@ export const ensureDocxXpath = ( )(file); }; +export const ensurePptxXpath = ( + file: string, + slideNumber: number, + selectors: string[], + noMatchSelectors?: string[], +): Verify => { + return verifyPptxDocument( + xmlChecker(selectors, noMatchSelectors), + "Inspecting Pptx for XPath selectors", + )(file, slideNumber); +}; + export const ensureDocxRegexMatches = ( file: string, regexes: (string | RegExp)[], From 5fb9b3a31a777385571016673149e2fbc5fd1212 Mon Sep 17 00:00:00 2001 From: Christophe Dervieux Date: Tue, 14 May 2024 12:25:56 +0200 Subject: [PATCH 3/3] Add a test for typst table Ensure the figure is not wrap in a block that prevents the alignment to work. This #block was created by the unneeded `Div` that is now a scaffolded one. --- tests/docs/smoke-all/2024/04/26/9365.qmd | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/tests/docs/smoke-all/2024/04/26/9365.qmd b/tests/docs/smoke-all/2024/04/26/9365.qmd index 3057a45f79f..d5b36bef45c 100644 --- a/tests/docs/smoke-all/2024/04/26/9365.qmd +++ b/tests/docs/smoke-all/2024/04/26/9365.qmd @@ -1,6 +1,6 @@ --- title: Parsed HTML table in PPTX -format: pptx +keep-typ: true _quarto: tests: pptx: @@ -8,9 +8,13 @@ _quarto: - 2 - ['//a:tbl'] - [] + typst: + ensureTypstFileRegexMatches: + - ['[\s]*#figure\('] + - ['[\s]*#block\[[\s]*#figure\('] --- -# Test table +# Test table {#test-table} ```{=html} @@ -31,5 +35,4 @@ _quarto:
-``` - +``` \ No newline at end of file