feat(runtime): implement single-article consolidation runtime and modularize codebase
This commit is contained in:
@@ -0,0 +1,44 @@
|
||||
"""Grounded intermediate Markdown assembler."""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from typing import List, Optional
|
||||
|
||||
from src.runtime.candidate.models import CandidateObject
|
||||
|
||||
|
||||
def assemble_intermediate_markdown(
|
||||
title: str,
|
||||
subtitle: Optional[str],
|
||||
ordered_blocks: List[CandidateObject],
|
||||
) -> str:
|
||||
"""Assembles sanitized intermediate Markdown from validated editorial components."""
|
||||
parts: List[str] = []
|
||||
|
||||
# Title as H1
|
||||
clean_title = title.strip()
|
||||
parts.append(f"# {clean_title}")
|
||||
|
||||
# Subtitle if present
|
||||
if subtitle and subtitle.strip():
|
||||
parts.append(f"*{subtitle.strip()}*")
|
||||
|
||||
# Ordered body blocks
|
||||
for blk in ordered_blocks:
|
||||
b_text = blk.text.strip()
|
||||
if not b_text:
|
||||
continue
|
||||
|
||||
if blk.type == "heading":
|
||||
level = blk.level or 2
|
||||
prefix = "#" * max(2, min(6, level))
|
||||
parts.append(f"{prefix} {b_text}")
|
||||
elif blk.type == "list_item":
|
||||
parts.append(f"- {b_text}")
|
||||
elif blk.type == "quote":
|
||||
parts.append(f"> {b_text}")
|
||||
else:
|
||||
# Standard paragraph
|
||||
parts.append(b_text)
|
||||
|
||||
return "\n\n".join(parts)
|
||||
Reference in New Issue
Block a user