Skip to content

Commit 021ecce

Browse files
claude: Support dot-joined language syntax like {python.marimo}
Update regexes in break-quarto-md.ts and pandoc-partition.ts to allow dots in language names. This is compatible with pampa executable cell syntax and also with the preferred class syntax {python .marimo}. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
1 parent 0dfc3c8 commit 021ecce

4 files changed

Lines changed: 39 additions & 3 deletions

File tree

‎src/core/lib/break-quarto-md.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ export async function breakQuartoMd(
4444
// regexes
4545
const yamlRegEx = /^---\s*$/;
4646
const startCodeCellRegEx = startCodeCellRegex || new RegExp(
47-
"^\\s*(```+)\\s*\\{([=A-Za-z]+)( *[ ,].*)?\\}\\s*$",
47+
"^\\s*(```+)\\s*\\{([=A-Za-z][=A-Za-z0-9._]*)( *[ ,].*)?\\}\\s*$",
4848
);
4949
const startCodeRegEx = /^```/;
5050
const endCodeRegEx = /^\s*(```+)\s*$/;

‎src/core/pandoc/pandoc-partition.ts‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,8 @@ export function languagesWithClasses(
119119
): Map<string, string | undefined> {
120120
const result = new Map<string, string | undefined>();
121121
// Capture language and everything after it (including dot-joined classes like {python.marimo})
122-
const kChunkRegex = /^[\t >]*```+\s*\{([a-zA-Z0-9_]+)([^}]*)?\}\s*$/gm;
122+
const kChunkRegex =
123+
/^[\t >]*```+\s*\{([a-zA-Z][a-zA-Z0-9_.]*)([^}]*)?\}\s*$/gm;
123124
kChunkRegex.lastIndex = 0;
124125
let match = kChunkRegex.exec(markdown);
125126
while (match) {

‎tests/unit/break-quarto-md/break-quarto-md.test.ts‎

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,3 +133,19 @@ And what about this?
133133
const cells = (await breakQuartoMd(qmd, false)).cells;
134134
assert(cells.length <= 2 || cells[2].cell_type === "markdown");
135135
});
136+
137+
unitTest("break-quarto-md - dot-joined language", async () => {
138+
await initYamlIntelligenceResourcesFromFilesystem();
139+
const qmd = `\`\`\`{python.marimo}
140+
x = 1
141+
\`\`\`
142+
`;
143+
const cells = (await breakQuartoMd(qmd, false)).cells;
144+
// First cell should be the code cell with language "python.marimo"
145+
assert(cells.length >= 1, "Should have at least one cell");
146+
assert(typeof cells[0].cell_type === "object", "First cell should be a code cell");
147+
assert(
148+
(cells[0].cell_type as { language: string }).language === "python.marimo",
149+
"Language should be 'python.marimo'",
150+
);
151+
});

‎tests/unit/pandoc-partition.test.ts‎

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
*/
77
import { assert } from "testing/asserts";
88
import { Metadata } from "../../src/config/types.ts";
9-
import { partitionMarkdown } from "../../src/core/pandoc/pandoc-partition.ts";
9+
import { languagesWithClasses, partitionMarkdown } from "../../src/core/pandoc/pandoc-partition.ts";
1010
import { unitTest } from "../test.ts";
1111

1212
// deno-lint-ignore require-await
@@ -54,3 +54,22 @@ unitTest("partitionYaml", async () => {
5454
"Heading missing attribute value",
5555
);
5656
});
57+
58+
// deno-lint-ignore require-await
59+
unitTest("languagesWithClasses - dot-joined syntax", async () => {
60+
const md = `\`\`\`{python.marimo}
61+
x = 1
62+
\`\`\`
63+
64+
\`\`\`{python .foo}
65+
y = 2
66+
\`\`\`
67+
`;
68+
const result = languagesWithClasses(md);
69+
// {python.marimo} → language "python.marimo", no class
70+
assert(result.has("python.marimo"), "Should have language 'python.marimo'");
71+
assert(result.get("python.marimo") === undefined, "python.marimo should have no class");
72+
// {python .foo} → language "python", class "foo"
73+
assert(result.has("python"), "Should have language 'python'");
74+
assert(result.get("python") === "foo", "python should have class 'foo'");
75+
});

0 commit comments

Comments
 (0)