Skip to content

Commit 813cbf1

Browse files
mscolnickakshaykapre-commit-ci[bot]
authored andcommitted
break: markdown width clamped for more readable typography (#4551)
Fixes #4548 This is a stylistic breaking change. We previously would make the output 100% regardless of whether it was markdown or not. Now: we make the output 100% width only for non-markdown. Markdown has it's own `max-width` set to `65ch` from the [tailwind typography](https://github.com/tailwindlabs/tailwindcss-typography) defaults. This can be unset via custom css in [app config](https://docs.marimo.io/guides/configuration/theming/), user config, or project config. To unset this add the css: ```css .markdown { max-width: unset !important; } ``` ------ <img width="1800" alt="image" src="https://github.com/user-attachments/assets/6c5db7fd-afb9-40cd-88c3-6f5006ef7042" /> ------- This is inline with how Observable does it as well (thanks to @manzt for pointing this out to me ealier this week unrelated to #4548) --------- Co-authored-by: Akshay Agrawal <akshay@marimo.io> Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
1 parent f876818 commit 813cbf1

File tree

8 files changed

+75
-4
lines changed

8 files changed

+75
-4
lines changed
Binary file not shown.

docs/guides/configuration/theming.md

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,15 @@ To include a custom CSS file, in the configuration dropdown, add the relative fi
88
app = marimo.App(css_file="custom.css")
99
```
1010

11+
## Theming at the project level
12+
13+
You may also set the `custom_css` field in your project configuration to apply a custom CSS file. This theme won't be applied if the notebook is shared with someone else, but it will be applied to all notebooks open inside the project.
14+
15+
```toml title="pyproject.toml"
16+
[tool.marimo.display]
17+
custom_css = ["additional.css"]
18+
```
19+
1120
## CSS Variables
1221

1322
We support only a few CSS variables as part of the "public API" for theming. These are:
@@ -64,12 +73,12 @@ You can target a cell's styles from the `data-cell-name` attribute. You can also
6473

6574
```css
6675
/* Target the cell named "My Cell" */
67-
[data-cell-name="my_cell"] {
76+
[data-cell-name='my_cell'] {
6877
background-color: light-dark(navy, pink);
6978
}
7079

7180
/* Target the output of the cell named "My Cell" */
72-
[data-cell-name="my_cell"] [data-cell-role="output"] {
81+
[data-cell-name='my_cell'] [data-cell-role='output'] {
7382
background-color: light-dark(navy, pink);
7483
}
7584
```

frontend/src/components/editor/output/Outputs.css

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,24 @@
2626
max-width: 100%;
2727
}
2828

29+
.output {
30+
/* Unset max-width on .markdown. Instead, we will apply
31+
to individual elements so it does not affect UI elements in markdown. */
32+
.markdown {
33+
max-width: unset;
34+
35+
> pre,
36+
> ul,
37+
div.codehilite,
38+
/* Target <span> that is not empty and does not consist entirely of child elements;
39+
* this makes sure text with embedded HTML (such as a slider) has a max width,
40+
* but standalone elements (like tables, plots) don't get a max width. */
41+
> span.paragraph:not(:has(> :only-child)):not(:empty) {
42+
max-width: var(--markdown-max-width);
43+
}
44+
}
45+
}
46+
2947
.stdout,
3048
.stderr,
3149
.marimo-error {

frontend/src/css/globals.css

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,8 @@
4444
--text-font: var(--marimo-text-font, "PT Sans", sans-serif);
4545
--heading-font: var(--marimo-heading-font, "Lora", serif);
4646
--radius: 8px;
47+
/* stylelint-disable-next-line unit-allowed-list */
48+
--markdown-max-width: 80ch;
4749

4850
/* Radix light colors: https://github.com/radix-ui/colors/blob/main/src/light.ts */
4951

frontend/src/css/katex.min.css

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
font-size: 110%;
77
line-height: inherit;
88
text-indent: 0;
9+
max-width: var(--markdown-max-width);
910
}
1011

1112
.katex * {

frontend/src/css/md.css

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
}
1313

1414
.markdown h1 {
15-
text-align: center;
15+
text-align: start;
1616
}
1717

1818
.config-width-full .markdown h1 {

marimo/_runtime/control_flow.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ def stop(predicate: bool, output: Optional[object] = None) -> None:
3838
```
3939
4040
Raises:
41-
MarimoStopError: When `predicate` is `True`, raises a `MarimoStopError`.
41+
MarimoStopError: When `predicate` is `True`
4242
"""
4343
if predicate:
4444
raise MarimoStopError(output)
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
2+
3+
import marimo
4+
5+
__generated_with = "0.12.9"
6+
app = marimo.App(width="medium")
7+
8+
9+
@app.cell
10+
def _():
11+
import marimo as mo
12+
13+
md = mo.md(
14+
"> long text goes here long text goes here long text goes here long text goes here long text goes here long text goes here long text goes here long text goes here long text goes here long text goes here long text goes here long text goes here long text goes here long text goes here"
15+
)
16+
md
17+
return md, mo
18+
19+
20+
@app.cell
21+
def _():
22+
import polars as pl
23+
24+
pl.DataFrame({"A": [1, 2, 3]})
25+
return
26+
27+
28+
@app.cell
29+
def _(md, mo):
30+
mo.vstack([md])
31+
return
32+
33+
34+
@app.cell
35+
def _(md, mo):
36+
mo.vstack([mo.hstack([md])])
37+
return
38+
39+
40+
if __name__ == "__main__":
41+
app.run()

0 commit comments

Comments
 (0)