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
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ This repo is a quarto engine extension that lets you use marimo in your quarto d
> **Requires Quarto >= 1.9.20** (pre-release). This extension uses the [engine extension API](https://quarto.org/docs/extensions/engines.html) introduced in 1.9.20.
> Install with: `quarto update --pre-release`

> [!NOTE]
> **This extension works best with marimo 0.14.16.** As such, it is currently pinned to marimo ==0.14.16. This notice will be updated when compatibility with future marimo versions is confirmed. You can override the pinned version by setting the `QUARTO_MARIMO_VERSION` environment variable.

### Quick Start

**1.** Tool Installation
Expand Down
16 changes: 7 additions & 9 deletions _extensions/marimo/extract.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import re
import sys
from collections.abc import Callable
from typing import Any, Optional
from typing import Any, ClassVar, Optional

# Native to python
from xml.etree.ElementTree import Element
Expand Down Expand Up @@ -95,10 +95,10 @@ def get_mime_render(
# Handle mimebundle - extract image data if present
if mimetype == "application/vnd.marimo+mimebundle":
try:
bundle = (
bundle: dict[str, Any] = (
json.loads(output.data)
if isinstance(output.data, str)
else output.data
else output.data # type: ignore[assignment]
)
# Look for image data in the bundle
for key in ["image/png", "image/jpeg", "image/svg+xml"]:
Expand All @@ -117,9 +117,7 @@ def get_mime_render(
}
except (json.JSONDecodeError, TypeError):
pass # Fall through to default handling
if mimetype.startswith("text/plain") or mimetype.startswith(
"text/markdown"
):
if mimetype.startswith(("text/plain", "text/markdown")):
return {"type": "para", "value": f"{output.data}", **render_options}
if mimetype == "application/vnd.marimo+error":
if config["error"]:
Expand Down Expand Up @@ -200,7 +198,7 @@ def tree_to_pandoc_export(root: Element) -> SafeWrap: # type: ignore[valid-type
code,
is_raw=True,
)
except Exception:
except Exception: # noqa: BLE001
stubs.append((config, None))
continue

Expand All @@ -218,7 +216,7 @@ def tree_to_pandoc_export(root: Element) -> SafeWrap: # type: ignore[valid-type

if global_options.get("eval", True):
_ = asyncio.run(app.build())
dev_server = os.environ.get("QUARTO_MARIMO_DEBUG_ENDPOINT", False)
dev_server = os.environ.get("QUARTO_MARIMO_DEBUG_ENDPOINT") or False
version_override = os.environ.get("QUARTO_MARIMO_VERSION", marimo.__version__)
header = app.render_head(
_development_url=dev_server, version_override=version_override
Expand All @@ -242,7 +240,7 @@ class MarimoPandocParser(MarimoParser): # type: ignore[misc]
"""Parses Markdown to marimo notebook string."""

# TODO: Could upstream generic for keys- but this is fine.
output_formats = { # type: ignore[assignment, misc]
output_formats: ClassVar[dict[str, Any]] = { # type: ignore[assignment, misc]
"marimo-pandoc-export": build_export_with_mime_context(mime_sensitive=False), # type: ignore[dict-item]
"marimo-pandoc-export-with-mime": build_export_with_mime_context(
mime_sensitive=True
Expand Down
Loading