Skip to content

Commit cd843d2

Browse files
authored
fix markdown .center, .right, .left not respecting new lines (#9326)
## 📝 Summary <!-- If this PR closes any issues, list them here by number (e.g., Closes #123). Detail the specific changes made in this pull request. Explain the problem addressed and how it was resolved. If applicable, provide before and after comparisons, screenshots, or any relevant details to help reviewers understand the changes easily. --> Wraps in a div with vstack instead of hstack. Use _BlockWrapped because plain vstacks were causing additional spacing to be added between divs. Before: <img width="1144" height="582" alt="image" src="https://github.com/user-attachments/assets/481661d4-135a-4d44-a2ac-0177ae5a8621" /> After: <img width="1147" height="675" alt="image" src="https://github.com/user-attachments/assets/4aa8ede4-0d0d-471a-a0fd-3803a039918c" /> ## 📋 Pre-Review Checklist <!-- These checks need to be completed before a PR is reviewed --> - [ ] For large changes, or changes that affect the public API: this change was discussed or approved through an issue, on [Discord](https://marimo.io/discord?ref=pr), or the community [discussions](https://github.com/marimo-team/marimo/discussions) (Please provide a link if applicable). - [x] Any AI generated code has been reviewed line-by-line by the human PR author, who stands by it. - [x] Video or media evidence is provided for any visual changes (optional). <!-- PR is more likely to be merged if evidence is provided for changes made --> ## ✅ Merge Checklist - [x] I have read the [contributor guidelines](https://github.com/marimo-team/marimo/blob/main/CONTRIBUTING.md). - [ ] Documentation has been updated where applicable, including docstrings for API changes. - [x] Tests have been added for the changes made.
1 parent e6b956a commit cd843d2

4 files changed

Lines changed: 465 additions & 7 deletions

File tree

examples/ui/layout.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
import marimo
99

10-
__generated_with = "0.19.7"
10+
__generated_with = "0.23.2"
1111
app = marimo.App()
1212

1313

marimo/_output/hypertext.py

Lines changed: 30 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,7 @@ def center(self) -> Html:
204204
"""
205205
from marimo._plugins.stateless import flex
206206

207-
return flex.hstack([self], justify="center")
207+
return flex.vstack([_BlockWrapped(self)], align="center", gap=0)
208208

209209
@mddoc
210210
def right(self) -> Html:
@@ -220,7 +220,7 @@ def right(self) -> Html:
220220
"""
221221
from marimo._plugins.stateless import flex
222222

223-
return flex.hstack([self], justify="end")
223+
return flex.vstack([_BlockWrapped(self)], align="end", gap=0)
224224

225225
@mddoc
226226
def left(self) -> Html:
@@ -236,7 +236,7 @@ def left(self) -> Html:
236236
"""
237237
from marimo._plugins.stateless import flex
238238

239-
return flex.hstack([self], justify="start")
239+
return flex.vstack([_BlockWrapped(self)], align="start", gap=0)
240240

241241
@mddoc
242242
def callout(
@@ -289,6 +289,33 @@ def _repr_html_(self) -> str:
289289
return self.text
290290

291291

292+
class _BlockWrapped(Html):
293+
"""Wraps another Html in a plain block ``<div>``.
294+
295+
Used by :meth:`Html.center`, :meth:`Html.left`, and :meth:`Html.right`
296+
so that the wrapped content renders inside a single block container
297+
(preserving normal block flow and margin collapsing between inner
298+
elements) rather than becoming multiple flex-column siblings when the
299+
inner wrapper uses ``display: contents`` (as ``mo.md`` does).
300+
301+
The inner Html is re-rendered on every ``text`` access so mutable
302+
children (e.g. ``mo.status.spinner``) keep updating live.
303+
"""
304+
305+
def __init__(self, inner: Html) -> None:
306+
self._inner = inner
307+
super().__init__(self._build_text())
308+
309+
def _build_text(self) -> str:
310+
from marimo._output.builder import h
311+
312+
return h.div(self._inner.text)
313+
314+
@property
315+
def text(self) -> str:
316+
return self._build_text()
317+
318+
292319
MARIMO_NO_JS_KEY = "MARIMO_NO_JS"
293320

294321

0 commit comments

Comments
 (0)