Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/resources/filters/normalize/parsehtml.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
38 changes: 38 additions & 0 deletions tests/docs/smoke-all/2024/04/26/9365.qmd
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
---
title: Parsed HTML table in PPTX
keep-typ: true
_quarto:
tests:
pptx:
ensurePptxXpath:
- 2
- ['//a:tbl']
- []
typst:
ensureTypstFileRegexMatches:
- ['<test-table>[\s]*#figure\(']
- ['<test-table>[\s]*#block\[[\s]*#figure\(']
---

# Test table {#test-table}

```{=html}
<table>
<thead>
<tr>
<th>Sepal.Length</th>
<th>Sepal.Width</th>
</tr>
</thead>
<tbody>
<tr>
<td>5.1</td>
<td>3.5</td>
</tr>
<tr>
<td>4.9</td>
<td>3.0</td>
</tr>
</tbody>
</table>
```
2 changes: 2 additions & 0 deletions tests/smoke/smoke-all.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -98,6 +99,7 @@ function resolveTestSpecs(
ensureOdtXpath,
ensureJatsXpath,
ensurePptxRegexMatches,
ensurePptxXpath,
ensureSnapshotMatches
};

Expand Down
92 changes: 73 additions & 19 deletions tests/verify.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 <T>(file: string,
k: (xml: string) => Promise<T>) => {
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 <T>(
file: string,
k: (xml: string) => Promise<T>
) => {
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 <T>(
file: string,
slideNumber: number,
k: (xml: string) => Promise<T>
) => {
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",
Expand Down Expand Up @@ -432,6 +462,18 @@ export const verifyDocXDocument = (
});
};

export const verifyPptxDocument = (
callback: (doc: string) => Promise<void>,
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[],
Expand Down Expand Up @@ -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)[],
Expand Down