-
Notifications
You must be signed in to change notification settings - Fork 432
Expand file tree
/
Copy pathfoo-engine.js
More file actions
102 lines (85 loc) · 2.46 KB
/
foo-engine.js
File metadata and controls
102 lines (85 loc) · 2.46 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
// Minimal engine to test class-based engine override
// Claims {python.foo} blocks with priority 2 (higher than Jupyter's 1)
let quarto;
const fooEngineDiscovery = {
init: (quartoAPI) => {
quarto = quartoAPI;
},
name: "foo",
defaultExt: ".qmd",
defaultYaml: () => ["engine: foo"],
defaultContent: () => ["# Foo Engine Document"],
validExtensions: () => [".qmd"],
claimsFile: (_file, _ext) => false,
claimsLanguage: (language, firstClass) => {
// Claim python.foo with priority 2 (overrides Jupyter's 1)
if (language === "python" && firstClass === "foo") {
return 2;
}
return 0;
},
canFreeze: false,
generatesFigures: false,
launch: (context) => {
return {
name: "foo",
canFreeze: false,
markdownForFile: async (file) => {
return quarto.mappedString.fromFile(file);
},
target: async (file, _quiet, markdown) => {
if (!markdown) {
markdown = quarto.mappedString.fromFile(file);
}
const metadata = quarto.markdownRegex.extractYaml(markdown.value);
return {
source: file,
input: file,
markdown,
metadata,
};
},
partitionedMarkdown: async (file) => {
const markdown = quarto.mappedString.fromFile(file);
return quarto.markdownRegex.partition(markdown.value);
},
execute: async (options) => {
const chunks = await quarto.markdownRegex.breakQuartoMd(
options.target.markdown,
);
const processedCells = [];
for (const cell of chunks.cells) {
if (
typeof cell.cell_type === "object" &&
cell.cell_type.language === "python"
) {
const header = cell.sourceVerbatim.value.split(/\r?\n/)[0];
const hasClassFoo = /\.foo\b/.test(header);
if (hasClassFoo) {
processedCells.push(`::: {#foo-engine-marker .foo-engine-output}
**FOO ENGINE PROCESSED THIS BLOCK**
Original code:
\`\`\`python
${cell.source.value.trim()}
\`\`\`
:::
`);
continue;
}
}
processedCells.push(cell.sourceVerbatim.value);
}
return {
markdown: processedCells.join(""),
supporting: [],
filters: [],
};
},
dependencies: async (_options) => {
return { includes: {} };
},
postprocess: async (_options) => {},
};
},
};
export default fooEngineDiscovery;