Skip to content

Commit 84560b4

Browse files
Convert from Lua filter to TypeScript engine extension
- Rewrite marimo execution as a Quarto engine extension (TypeScript) - Support three cell syntaxes: {python .marimo}, {python.marimo}, python {.marimo} - Implement claimsLanguage for automatic engine detection (priority 2 for class syntax) - Add cell-execution-regex.ts with comprehensive test suite - Fix PDF output handling (mimebundle, raw HTML blocks) - Update all examples to use preferred {python .marimo} syntax - Requires quarto >= 1.9.19 Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
1 parent 0118cc6 commit 84560b4

26 files changed

+2096
-456
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,3 +23,5 @@ result
2323
# pixi environments
2424
.pixi
2525
*.egg-info
26+
27+
**/*.quarto_ipynb

README.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,4 +103,16 @@ Javascript.
103103

104104
---
105105

106+
## Development
107+
108+
To build the TypeScript engine extension:
109+
110+
```bash
111+
quarto call build-ts-extension
112+
```
113+
114+
This bundles `src/marimo-engine.ts` into `_extensions/marimo/marimo-engine.js`.
115+
116+
---
117+
106118
Credits: [holoviz-quarto](https://github.com/awesome-panel/holoviz-quarto) for ideas on layout

_extensions/marimo/_extension.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
title: Quarto Marimo Extension
2-
version: 0.4.3
3-
quarto-required: ">=1.3.0"
2+
version: 0.5.0
3+
quarto-required: ">=1.9.19"
44
contributes:
5-
filters:
6-
- marimo-execute.lua
5+
engines:
6+
- path: marimo-engine.js

_extensions/marimo/command.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ def extract_command(header: str) -> list[str]:
3131
mode="w", delete=False, suffix=".txt"
3232
) as temp_file:
3333
flags = construct_uv_flags(pyproject, temp_file, [], [])
34-
34+
temp_file.flush()
3535
return ["run"] + flags
3636

3737

_extensions/marimo/extract.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,19 @@ def get_mime_render(
9191
if config["output"] and mime_sensitive:
9292
if mimetype.startswith("image"):
9393
return {"type": "figure", "value": f"{output.data}", **render_options}
94+
# Handle mimebundle - extract image data if present
95+
if mimetype == "application/vnd.marimo+mimebundle":
96+
try:
97+
bundle = json.loads(output.data) if isinstance(output.data, str) else output.data
98+
# Look for image data in the bundle
99+
for key in ["image/png", "image/jpeg", "image/svg+xml"]:
100+
if key in bundle:
101+
return {"type": "figure", "value": bundle[key], **render_options}
102+
# Fall back to text if no image
103+
if "text/plain" in bundle:
104+
return {"type": "para", "value": bundle["text/plain"], **render_options}
105+
except (json.JSONDecodeError, TypeError):
106+
pass # Fall through to default handling
94107
if mimetype.startswith("text/plain") or mimetype.startswith(
95108
"text/markdown"
96109
):

0 commit comments

Comments
 (0)