Skip to content

Commit 022f9cd

Browse files
claude: refactor foo-engine test to use Quarto API
Use breakQuartoMd API for cell iteration instead of raw regex, making the code more idiomatic and fixing Windows CI failures caused by line ending differences. Also fix test syntax to use {python .foo} (space-separated) which is recognized by breakQuartoMd. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
1 parent e492c5e commit 022f9cd

File tree

2 files changed

+23
-13
lines changed

2 files changed

+23
-13
lines changed

tests/docs/smoke-all/engine/class-override/_extensions/foo-engine/foo-engine.js

Lines changed: 22 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -55,26 +55,36 @@ const fooEngineDiscovery = {
5555
},
5656

5757
execute: async (options) => {
58-
// Replace python.foo code blocks with a marker div showing we processed them
59-
let markdown = options.target.markdown.value;
60-
61-
// Find and replace {python.foo} blocks with our marker output
62-
const codeBlockRegex = /```\{python\.foo[^}]*\}\n([\s\S]*?)```/g;
63-
markdown = markdown.replace(codeBlockRegex, (match, code) => {
64-
return `
65-
::: {#foo-engine-marker .foo-engine-output}
58+
const chunks = await quarto.markdownRegex.breakQuartoMd(
59+
options.target.markdown,
60+
);
61+
62+
const processedCells = [];
63+
for (const cell of chunks.cells) {
64+
if (
65+
typeof cell.cell_type === "object" &&
66+
cell.cell_type.language === "python"
67+
) {
68+
const header = cell.sourceVerbatim.value.split(/\r?\n/)[0];
69+
const hasClassFoo = /\.foo\b/.test(header);
70+
if (hasClassFoo) {
71+
processedCells.push(`::: {#foo-engine-marker .foo-engine-output}
6672
**FOO ENGINE PROCESSED THIS BLOCK**
6773
6874
Original code:
6975
\`\`\`python
70-
${code.trim()}
76+
${cell.source.value.trim()}
7177
\`\`\`
7278
:::
73-
`;
74-
});
79+
`);
80+
continue;
81+
}
82+
}
83+
processedCells.push(cell.sourceVerbatim.value);
84+
}
7585

7686
return {
77-
markdown: markdown,
87+
markdown: processedCells.join(""),
7888
supporting: [],
7989
filters: [],
8090
};

tests/docs/smoke-all/engine/class-override/test.qmd

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ This document tests that `{python.foo}` blocks are processed by the foo-engine
1818
instead of Jupyter, because foo-engine claims `python` with `firstClass === "foo"`
1919
at priority 2 (higher than Jupyter's default of 1).
2020

21-
```{python.foo}
21+
```{python .foo}
2222
x = 1 + 1
2323
print(x)
2424
```

0 commit comments

Comments
 (0)