Skip to content
Open
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
11 changes: 11 additions & 0 deletions marimo/_output/formatters/iframe.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,15 @@
# Copyright 2025 Marimo. All rights reserved.
from __future__ import annotations

import re
from html.parser import HTMLParser

_SCRIPT_INLINE_RE = re.compile(
# matches <script ...> that does NOT have 'src=' before the close '>'
r"<script\b(?![^>]*\bsrc\s*=)",
re.IGNORECASE,
)


def maybe_wrap_in_iframe(html_content: str) -> str:
if _has_script_tag_without_src(html_content):
Expand All @@ -17,6 +24,10 @@ def _has_script_tag_without_src(html_content: str) -> bool:
if "<script" not in html_content:
return False

# Fast regex check for <script ...> without src
if not _SCRIPT_INLINE_RE.search(html_content):
return False

parser = ScriptTagParser()
try:
parser.feed(html_content) # type: ignore
Expand Down
5 changes: 2 additions & 3 deletions marimo/_output/formatting.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,9 +148,8 @@ def get_formatter(
get_context()
except ContextNotInitializedError:
if FORMATTERS.is_empty():
from marimo._output.formatters.formatters import (
register_formatters,
)
from marimo._output.formatters.formatters import \
register_formatters

# Install formatters when marimo is being used without
# a kernel (eg, in a unit test or when run as a Python script)
Expand Down