Skip to content

A reactive notebook for Python — run reproducible experiments, query with SQL, execute as a script, deploy as an app, and version with git. Stored as pure Python. All in a modern, AI-native editor.

chore: change 12px to text-xs for better compatible with vscode and other theming (#7178)

Myles Scolnick0cd169f05267
diff --git a/marimo/_output/builder.py b/marimo/_output/builder.py
index ce338ec239..438e7acee3 100644
--- a/marimo/_output/builder.py
+++ b/marimo/_output/builder.py
@@ -127,10 +127,16 @@ class _HTMLBuilder:
return f"<iframe {_join_params(params)}></iframe>"
@staticmethod
- def pre(child: str, style: Optional[str] = None) -> str:
+ def pre(
+ child: str,
+ style: Optional[str] = None,
+ class_: Optional[str] = None,
+ ) -> str:
params: list[tuple[str, Union[str, None]]] = []
if style is not None:
params.append(("style", style))
+ if class_ is not None:
+ params.append(("class", class_))
if not params:
return f"<pre>{child}</pre>"
diff --git a/marimo/_plugins/stateless/plain_text.py b/marimo/_plugins/stateless/plain_text.py
index c086165705..81ba3c04d0 100644
--- a/marimo/_plugins/stateless/plain_text.py
+++ b/marimo/_plugins/stateless/plain_text.py
@@ -6,7 +6,6 @@ import html
from marimo._output.builder import h
from marimo._output.hypertext import Html
from marimo._output.rich_help import mddoc
-from marimo._output.utils import create_style
@mddoc
@@ -19,6 +18,5 @@ def plain_text(text: str) -> Html:
Returns:
An `Html` object representing the text.
"""
- styles = create_style({"font-size": "12px"})
- img = h.pre(child=html.escape(text), style=styles)
+ img = h.pre(child=html.escape(text), class_="text-xs")
return Html(img)
diff --git a/tests/_output/formatters/test_structures.py b/tests/_output/formatters/test_structures.py
index 8bae83cf22..ba5b1a9402 100644
--- a/tests/_output/formatters/test_structures.py
+++ b/tests/_output/formatters/test_structures.py
@@ -193,7 +193,7 @@ def test_format_structure_subclasses_with_different_built_in_repr() -> None:
custom_list = CustomList()
assert get_and_format(custom_list) == (
"text/html",
- "<pre style='font-size: 12px'>CustomList(a=1, b=2, c=3)</pre>",
+ "<pre class='text-xs'>CustomList(a=1, b=2, c=3)</pre>",
)
class CustomDict(dict):
@@ -206,7 +206,7 @@ def test_format_structure_subclasses_with_different_built_in_repr() -> None:
custom_dict = CustomDict()
assert get_and_format(custom_dict) == (
"text/html",
- "<pre style='font-size: 12px'>CustomDict(a=1, b=2, c=3)</pre>",
+ "<pre class='text-xs'>CustomDict(a=1, b=2, c=3)</pre>",
)
class CustomTuple(tuple):
@@ -219,11 +219,11 @@ def test_format_structure_subclasses_with_different_built_in_repr() -> None:
custom_tuple = CustomTuple()
assert get_and_format(custom_tuple) == (
"text/html",
- "<pre style='font-size: 12px'>CustomTuple(a=1, b=2, c=3)</pre>",
+ "<pre class='text-xs'>CustomTuple(a=1, b=2, c=3)</pre>",
)
assert get_and_format(sys.version_info)[1].startswith(
- "<pre style='font-size: 12px'>sys.version_info(major=3"
+ "<pre class='text-xs'>sys.version_info(major=3"
)
diff --git a/tests/_output/test_try_format.py b/tests/_output/test_try_format.py
index e239d9487b..f5c67557a2 100644
--- a/tests/_output/test_try_format.py
+++ b/tests/_output/test_try_format.py
@@ -78,37 +78,28 @@ def is_html(output: FormattedOutput) -> bool:
def test_primitives():
# 1 and "1" are different
- assert try_format(1).data == "<pre style='font-size: 12px'>1</pre>"
- assert (
- try_format("1").data
- == "<pre style='font-size: 12px'>&#x27;1&#x27;</pre>"
- )
+ assert try_format(1).data == "<pre class='text-xs'>1</pre>"
+ assert try_format("1").data == "<pre class='text-xs'>&#x27;1&#x27;</pre>"
assert (
try_format("hello").data
- == "<pre style='font-size: 12px'>&#x27;hello&#x27;</pre>"
- )
- assert (
- try_format("").data
- == "<pre style='font-size: 12px'>&#x27;&#x27;</pre>"
+ == "<pre class='text-xs'>&#x27;hello&#x27;</pre>"
)
+ assert try_format("").data == "<pre class='text-xs'>&#x27;&#x27;</pre>"
assert try_format(None).data == ""
# True and 'True' are different
- assert try_format(True).data == "<pre style='font-size: 12px'>True</pre>"
+ assert try_format(True).data == "<pre class='text-xs'>True</pre>"
assert (
try_format("True").data
- == "<pre style='font-size: 12px'>&#x27;True&#x27;</pre>"
- )
- assert try_format(False).data == "<pre style='font-size: 12px'>False</pre>"
- assert try_format(1.0).data == "<pre style='font-size: 12px'>1.0</pre>"
- assert (
- try_format(1.0 + 1.0j).data
- == "<pre style='font-size: 12px'>(1+1j)</pre>"
+ == "<pre class='text-xs'>&#x27;True&#x27;</pre>"
)
+ assert try_format(False).data == "<pre class='text-xs'>False</pre>"
+ assert try_format(1.0).data == "<pre class='text-xs'>1.0</pre>"
+ assert try_format(1.0 + 1.0j).data == "<pre class='text-xs'>(1+1j)</pre>"
assert try_format([1, 2, 3]).data == "[1, 2, 3]"
assert try_format({"a": 1, "b": 2}).data == '{"a": 1, "b": 2}'
assert (
try_format(set([1, 2, 3])).data
- == "<pre style='font-size: 12px'>{1, 2, 3}</pre>"
+ == "<pre class='text-xs'>{1, 2, 3}</pre>"
)
@@ -160,7 +151,7 @@ def test_plain_object():
result = try_format(obj)
# Should fall back to string representation since we opted out of opinionated formatter
assert is_html(result)
- assert result.data.startswith("<pre style='font-size: 12px'>Plain(")
+ assert result.data.startswith("<pre class='text-xs'>Plain(")
def test_opinionated_formatter():
@@ -188,7 +179,7 @@ def test_does_not_use_only_str_repr():
obj = NoFormatter()
result = try_format(obj)
assert is_html(result)
- assert result.data.startswith("<pre style='font-size: 12px'>")
+ assert result.data.startswith("<pre class='text-xs'>")
assert "test_does_not_use_only_str_repr" in result.data.lower()
@@ -235,7 +226,7 @@ def test_repr_is_used_over_str():
obj = StrErrorTest()
result = try_format(obj)
assert is_html(result)
- assert result.data == "<pre style='font-size: 12px'>repr_value</pre>"
+ assert result.data == "<pre class='text-xs'>repr_value</pre>"
@pytest.mark.skipif(
@@ -248,4 +239,4 @@ def test_numpy_array():
obj = np.array([1, 2, 3])
result = try_format(obj)
assert is_html(result)
- assert result.data == "<pre style='font-size: 12px'>array([1, 2, 3])</pre>"
+ assert result.data == "<pre class='text-xs'>array([1, 2, 3])</pre>"
diff --git a/tests/_plugins/stateless/test_plain_text.py b/tests/_plugins/stateless/test_plain_text.py
index ceeead5ae6..6f33f72fe9 100644
--- a/tests/_plugins/stateless/test_plain_text.py
+++ b/tests/_plugins/stateless/test_plain_text.py
@@ -43,4 +43,4 @@ def test_plain_text_preserves_whitespace() -> None:
def test_plain_text_empty_string() -> None:
"""Test plain_text with empty string."""
result = plain_text("")
- assert result.text == "<pre style='font-size: 12px'></pre>"
+ assert result.text == "<pre class='text-xs'></pre>"
diff --git a/tests/_runtime/test_runtime.py b/tests/_runtime/test_runtime.py
index 12f7b9d7a7..c85133362e 100644
--- a/tests/_runtime/test_runtime.py
+++ b/tests/_runtime/test_runtime.py
@@ -1627,7 +1627,7 @@ except NameError:
assert m1["status"] == "queued"
assert m2["status"] == "running"
assert m3["status"] is None
- assert m3["output"]["data"] == "<pre style='font-size: 12px'>1</pre>"
+ assert m3["output"]["data"] == "<pre class='text-xs'>1</pre>"
assert m4["status"] == "idle"
# Does not pollute globals
assert "x" not in k.globals
@@ -1654,8 +1654,7 @@ except NameError:
messages = stream.operations
output_message = messages[-2]
assert (
- output_message["output"]["data"]
- == "<pre style='font-size: 12px'>20</pre>"
+ output_message["output"]["data"] == "<pre class='text-xs'>20</pre>"
)
assert "z" in k.globals
# Does not pollute globals
@@ -1683,8 +1682,7 @@ except NameError:
messages = stream.operations
output_message = messages[-2]
assert (
- output_message["output"]["data"]
- == "<pre style='font-size: 12px'>20</pre>"
+ output_message["output"]["data"] == "<pre class='text-xs'>20</pre>"
)
assert "z" in k.globals
# Does not pollute globals, reverts back to 10
diff --git a/tests/_server/api/endpoints/test_export.py b/tests/_server/api/endpoints/test_export.py
index d00c9e787c..b5a14ddab6 100644
--- a/tests/_server/api/endpoints/test_export.py
+++ b/tests/_server/api/endpoints/test_export.py
@@ -478,7 +478,7 @@ def test_auto_export_ipynb_with_new_cell(
# Wait for the ipynb file to be created
time.sleep(0.2)
notebook = ipynb_path.read_text()
- assert "<pre style='font-size: 12px'>3.14</pre>" in notebook
+ assert "<pre class='text-xs'>3.14</pre>" in notebook
@with_session(SESSION_ID)
diff --git a/tests/_server/export/snapshots/notebook_with_outputs.ipynb.txt b/tests/_server/export/snapshots/notebook_with_outputs.ipynb.txt
index 9c36303b29..f7f53128cc 100644
--- a/tests/_server/export/snapshots/notebook_with_outputs.ipynb.txt
+++ b/tests/_server/export/snapshots/notebook_with_outputs.ipynb.txt
@@ -64,7 +64,7 @@
{
"data": {
"text/html": [
- "<pre style='font-size: 12px'>22</pre>"
+ "<pre class='text-xs'>22</pre>"
]
},
"metadata": {},
diff --git a/tests/_server/export/snapshots/run_until_completion_with_stack_trace.txt b/tests/_server/export/snapshots/run_until_completion_with_stack_trace.txt
index bc929167c5..acf331dd59 100644
--- a/tests/_server/export/snapshots/run_until_completion_with_stack_trace.txt
+++ b/tests/_server/export/snapshots/run_until_completion_with_stack_trace.txt
@@ -7,7 +7,7 @@
"status": "idle"
},
{
- "output": "<pre style='font-size: 12px'>15</pre>",
+ "output": "<pre class='text-xs'>15</pre>",
"console": [
"internal error\n"
],
@@ -27,4 +27,4 @@
],
"status": "idle"
}
-]
\ No newline at end of file
+]