diff --git a/py/services/agent/skills/enrich_hf_metadata/md_to_html.py b/py/services/agent/skills/enrich_hf_metadata/md_to_html.py index 9664d310..58356f85 100644 --- a/py/services/agent/skills/enrich_hf_metadata/md_to_html.py +++ b/py/services/agent/skills/enrich_hf_metadata/md_to_html.py @@ -65,26 +65,30 @@ def extract_gallery_images( entry = entry.strip() - # Extract text (prompt) + # Extract text (prompt) — handles three YAML scalar styles: + # 1. "quoted inline" + # 2. >- folded block + # 3. plain (unquoted) multi-line text = "" - # Quoted inline: `"some prompt"` qm = re.match(r'^"((?:[^"\\]|\\.)*)"', entry) if qm: text = qm.group(1) else: - # Multi-line YAML scalar: `>-\n line1\n line2` mm = re.match(r"^>(?:-\s*)?\n((?:.+(?:\n|$))+)", entry, re.MULTILINE) if mm: raw = mm.group(1) - # Take lines until a line starts with a YAML key (word + colon) + else: + # Plain YAML scalar — take lines until a YAML key + raw = entry + if raw: text_lines: list[str] = [] for line in raw.split("\n"): if re.match(r"^\s*\w+:", line): break - text_lines.append(line) - text = " ".join( - line.strip() for line in text_lines if line.strip() - ) + stripped = line.strip() + if stripped: + text_lines.append(stripped) + text = " ".join(text_lines) # Extract output.url url = "" diff --git a/tests/agent_cli/test_agent_cli.py b/tests/agent_cli/test_agent_cli.py index 3071184e..0e393d36 100644 --- a/tests/agent_cli/test_agent_cli.py +++ b/tests/agent_cli/test_agent_cli.py @@ -566,3 +566,20 @@ base_model: flux ) == "prithivMLmods/Flux-Long-Toon-LoRA" assert extract_repo_from_hf_url("") == "" assert extract_repo_from_hf_url("not a url") == "" + + def test_plain_yaml_scalar_text(self): + """Unquoted multi-line YAML scalar (plain format) should extract prompt.""" + from py.services.agent.skills.enrich_hf_metadata.md_to_html import \ + extract_gallery_images + + md = """--- +widget: +- text: two samurais doing a muay thai fight + while the other leans back. Textured abstract style + output: + url: images/00.png +---""" + images = extract_gallery_images(md, "user/repo") + assert len(images) == 1 + assert "two samurais doing a muay thai fight" in images[0]["meta"]["prompt"] + assert "Textured abstract style" in images[0]["meta"]["prompt"]