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.
Python artificial-intelligencedagdata-sciencedata-visualizationdataflowdeveloper-toolsmachine-learningnotebookspipelinepythonreactivesqlweb-app
style fix for li & ol: reduce margin and restore original disc (#8768)
Shahmir Varqhab93da60ae8ea
diff --git a/frontend/src/css/md.css b/frontend/src/css/md.cssindex 4a80026bb2..b11a53c045 100644--- a/frontend/src/css/md.css+++ b/frontend/src/css/md.css@@ -12,6 +12,16 @@margin-block-end: 0;}+.markdown ul li,+.markdown ol li {+ margin-block: 0;+}++/* Restore browser default bullet cycling that Tailwind Typography overrides */+.markdown ul ul {+ list-style-type: revert;+}+.markdown h1 {text-align: start;}diff --git a/marimo/_output/md_extensions/breakless_lists.py b/marimo/_output/md_extensions/breakless_lists.pyindex 630b4ef359..18cdda1e81 100644--- a/marimo/_output/md_extensions/breakless_lists.py+++ b/marimo/_output/md_extensions/breakless_lists.py@@ -68,22 +68,39 @@ class BreaklessListsTreeProcessor(treeprocessors.Treeprocessor): # type: ignoreThis makes lists more compact by removing <p> tags within <li> elements."""- def run(self, root: Element) -> None:- def is_only_child(parent: Element, child: Element) -> bool:- return len(parent) == 1 and parent[0] is child+ LIST_TAGS = {"ul", "ol"}+ def run(self, root: Element) -> None:for element in root.iter(tag="li"):- for p in element.findall(".//p"):- # If paragraph has no attributes and is the only child- if not p.attrib and is_only_child(element, p):- # Swap the paragraph with the list item- element.text = p.text- element.tail = p.tail- # Copy over the children- for child in p:- element.append(child)- # Remove the paragraph tag- element.remove(p)+ self._unwrap_single_paragraph(element)++ def _unwrap_single_paragraph(self, li: Element) -> None:+ """Unwrap a <p> inside an <li> when it's safe to do so.++ Safe cases:+ - <li><p>text</p></li> (only child)+ - <li><p>text</p><ul>...</ul></li> (one p + nested lists)++ Unsafe (preserved):+ - <li><p>para1</p><p>para2</p></li> (multi-paragraph)+ """+ direct_ps = [c for c in li if c.tag == "p" and not c.attrib]+ if len(direct_ps) != 1:+ return++ p = direct_ps[0]+ others = [c for c in li if c is not p]+ if not all(c.tag in self.LIST_TAGS for c in others):+ return++ # Lift p's text onto the li, preserving children.+ # p.tail (whitespace between </p> and the next sibling) is+ # intentionally dropped — markdown output only puts newlines there.+ li.text = p.text+ idx = list(li).index(p)+ for i, child in enumerate(p):+ li.insert(idx + i, child)+ li.remove(p)class BreaklessListsExtension(Extension): # type: ignore[misc]diff --git a/marimo/_smoke_tests/markdown/sane_lists.py b/marimo/_smoke_tests/markdown/sane_lists.pyindex 0147fbcaca..60e0097a01 100644--- a/marimo/_smoke_tests/markdown/sane_lists.py+++ b/marimo/_smoke_tests/markdown/sane_lists.py@@ -1,145 +1,135 @@import marimo-__generated_with = "0.16.2"+__generated_with = "0.21.1"app = marimo.App(width="columns")@app.cell(column=0, hide_code=True)def _(mo):- mo.md(r"""## Random numbering""")+ mo.md(r"""+ ## Random numbering+ """)return@app.celldef _(mo):- mo.md(- """+ mo.md("""2. hey2. hey2. hey- """- )+ """)return@app.celldef _(mo):- mo.md(- """+ mo.md("""1. hey1. hey1. hey- """- )+ """)return@app.celldef _(mo):- mo.md(- r"""+ mo.md(r"""1. hey2. hey2. hey- """- )+ """)return@app.cell(column=1, hide_code=True)def _(mo):- mo.md(r"""## List without breaks""")+ mo.md(r"""+ ## List without breaks+ """)return@app.celldef _(mo):- mo.md(- r"""+ mo.md(r"""Lists with new line break (GitHub supports this)- hey- hey- hey- """- )+ """)return@app.celldef _(mo):- mo.md(- r"""+ mo.md(r"""Lists with new line break (GitHub supports this)1. one2. two- two two- """- )+ """)return@app.cell(column=2, hide_code=True)def _(mo):- mo.md(r"""## List with 2 or 4 indentation""")+ mo.md(r"""+ ## List with 2 or 4 indentation+ """)return@app.celldef _(mo):- mo.md(- r"""+ mo.md(r"""Lists with 2-space indents (GitHub supports this)- hey- hey- hey- """- )+ - hey+ """)return@app.celldef _(mo):- mo.md(- r"""+ mo.md(r"""Lists with 4-space indents (GitHub supports this)1. hey1. hey2. hey- """- )+ """)return@app.celldef _(mo):- mo.md(- r"""+ mo.md(r"""1. Item 11. Nested ordered item1. Deep nested ordered2. Item 2- """- )+ """)return@app.celldef _(mo):- mo.md(- r"""+ mo.md(r"""- List- indent with 3 spaces- indent with 6 spaces- """- )+ """)return@app.celldef _():import marimo as mo+return (mo,)diff --git a/tests/_output/test_md.py b/tests/_output/test_md.pyindex b415915aac..c2fd3cc3fc 100644--- a/tests/_output/test_md.py+++ b/tests/_output/test_md.py@@ -158,12 +158,8 @@ def test_md_flexible_indent_spaces(spaces: int) -> None:assert result == snapshot("""\<ul>-<li>-<span class="paragraph">Item 1</span>-<ul>-<li>-<span class="paragraph">Nested item</span>-<ul>+<li>Item 1<ul>+<li>Nested item<ul><li>Deep nested</li></ul></li>@@ -188,12 +184,8 @@ def test_md_flexible_indent_mixed_normalization() -> None:assert result == snapshot("""\<ul>-<li>-<span class="paragraph">Item 1</span>-<ul>-<li>-<span class="paragraph">Nested item (3 spaces, should normalize to 2 or 4)</span>-<ul>+<li>Item 1<ul>+<li>Nested item (3 spaces, should normalize to 2 or 4)<ul><li>Deep nested (6 spaces)</li></ul></li>@@ -219,12 +211,8 @@ def test_md_flexible_indent_ordered_lists(spaces: int) -> None:assert result == snapshot("""\<ol>-<li>-<span class="paragraph">Item 1</span>-<ol>-<li>-<span class="paragraph">Nested ordered item</span>-<ol>+<li>Item 1<ol>+<li>Nested ordered item<ol><li>Deep nested ordered</li></ol></li>@@ -236,6 +224,90 @@ def test_md_flexible_indent_ordered_lists(spaces: int) -> None:)+def test_md_nested_list_no_paragraph_wrapper() -> None:+ # Nested list items should not have <p>/<span class="paragraph"> wrappers+ input_text = """- Item 1+ - Nested item+- Item 2"""++ result = _md(input_text, apply_markdown_class=False).text+ assert result == snapshot(+ """\+<ul>+<li>Item 1<ul>+<li>Nested item</li>+</ul>+</li>+<li>Item 2</li>+</ul>\+"""+ )+ assert '<span class="paragraph">' not in result+++def test_md_nested_list_preserves_multi_paragraph() -> None:+ input_text = """- Paragraph one++ Paragraph two++- Item 2"""++ result = _md(input_text, apply_markdown_class=False).text+ assert result == snapshot(+ """\+<ul>+<li>+<span class="paragraph">Paragraph one</span>+<span class="paragraph">Paragraph two</span>+</li>+<li>Item 2</li>+</ul>\+"""+ )+++def test_md_nested_list_with_inline_elements() -> None:+ # Inline elements like bold/italic/code should survive p-unwrapping+ input_text = """- **Bold item**+ - *Nested italic*+ - `code item`"""++ result = _md(input_text, apply_markdown_class=False).text+ assert result == snapshot(+ """\+<ul>+<li><strong>Bold item</strong></li>+<li><em>Nested italic</em><ul>+<li><code>code item</code></li>+</ul>+</li>+</ul>\+"""+ )+++def test_md_nested_mixed_list_types() -> None:+ # Mixed ordered/unordered nested lists should unwrap correctly+ input_text = """1. Ordered item+ - Unordered nested+ - Another nested+2. Second ordered"""++ result = _md(input_text, apply_markdown_class=False).text+ assert result == snapshot(+ """\+<ol>+<li>Ordered item<ul>+<li>Unordered nested</li>+<li>Another nested</li>+</ul>+</li>+<li>Second ordered</li>+</ol>\+"""+ )++def test_md_breakless_lists_with_paragraphs() -> None:# Test CommonMark-style list interruptioninput_text_no_blank = """This is GitHub-flavored markdown: