Local UI to run and train LLMs and diffusion models. Supports GGUF, MLX, Qwen3.8, DeepSeek-V4.1, MiniMax-H3, Gemma 4, FLUX and more.
Python agentaichatgptdeepseekfine-tuninggemmaimage-generationllamallmllmsopenaipythonqwenreinforcement-learningself-hostedstable-diffusiontext-to-speechttsuiunsloth
Studio: keep a list item's first paragraph on its bullet in fetched pages (#12179)
Mohammad Hijjawid1f6cb5cf701
diff --git a/studio/backend/core/inference/_html_to_md.py b/studio/backend/core/inference/_html_to_md.pyindex 9198e8f95e1..2fd8f2808d3 100644--- a/studio/backend/core/inference/_html_to_md.py+++ b/studio/backend/core/inference/_html_to_md.py@@ -334,6 +334,8 @@ class _MarkdownRenderer(HTMLParser):self._list_stack: list[str] = [] # "ul" or "ol"self._ol_counter: list[int] = []+ # Just emitted a list marker: a block opening the item (loose <li><p>) stays on the marker line.+ self._li_marker_pending: bool = Falseself._in_table: bool = Falseself._current_row: list[str] = []@@ -367,6 +369,8 @@ class _MarkdownRenderer(HTMLParser):return len(self._bq_stack) > frame.outer_bq_depthdef _emit(self, text: str) -> None:+ if text:+ self._li_marker_pending = Falseframe = self._header_stack[-1] if self._header_stack else None# Tee wherever the text routes, so a heading in a nested buffer is captured. A link opened inside the frame# delivers twice, so tee only the formatted form; an enclosing link, once.@@ -724,7 +728,8 @@ class _MarkdownRenderer(HTMLParser):self._emit("\n")elif tag in _BLOCK_TAGS:- self._emit("\n\n")+ if not self._li_marker_pending:+ self._emit("\n\n")elif tag == "hr":self._emit("\n\n---\n\n")@@ -757,6 +762,7 @@ class _MarkdownRenderer(HTMLParser):self._emit(f"\n{indent}1. ")else:self._emit(f"\n{indent}* ")+ self._li_marker_pending = Trueelif tag == "pre":self._pre_parts = []@@ -799,7 +805,10 @@ class _MarkdownRenderer(HTMLParser):if not self._exit_tag(tag):return- if tag in _HEADING_TAGS:+ if tag == "li":+ self._li_marker_pending = False++ elif tag in _HEADING_TAGS:self._emit("\n\n")elif tag == "a":@@ -875,6 +884,9 @@ class _MarkdownRenderer(HTMLParser):# Suppress whitespace-only nodes between table elements (source indentation).if self._in_table and not self._in_cell and not text.strip():return+ # Source indentation between <li> and its first block must not end the marker line.+ if self._li_marker_pending and not text.strip():+ returnself._emit(text)def handle_entityref(self, name: str) -> None:diff --git a/studio/backend/tests/test_web_fetch_extraction.py b/studio/backend/tests/test_web_fetch_extraction.pyindex 38ef6c7492d..ea26582cb74 100644--- a/studio/backend/tests/test_web_fetch_extraction.py+++ b/studio/backend/tests/test_web_fetch_extraction.py@@ -345,6 +345,27 @@ def test_visible_void_hr_still_renders():assert "---" in out+ "html, expected",+ [+ (+ "<ul>\n<li>\n<p>First item</p>\n</li>\n<li>\n<p>Second item</p>\n</li>\n</ul>",+ "* First item\n\n* Second item",+ ),+ ("<ol><li><p>One</p></li><li><div>Two</div></li></ol>", "1. One\n\n2. Two"),+ ("<ul><li><p>a</p><ul><li><p>b</p></li></ul></li></ul>", "* a\n\n * b"),+ ("<ul><li></li><p>outside</p></ul>", "*\n\noutside"),+ ],+)+def test_block_opening_list_item_stays_on_marker_line(html, expected):+ assert html_to_markdown(html) == expected+++def test_empty_header_does_not_consume_the_list_marker():+ html = "<ul><li><header></header><p>text text text</p></li></ul>"+ assert html_to_markdown(html, main_content = True) == "* text text text"++# ── html_to_markdown: main-content scoping ───────────────────────