-
Notifications
You must be signed in to change notification settings - Fork 1
Open
Description
Summary
Add an option to return rendered content without the SVG wrapper, along with dimensions. This allows callers to compose multiple mdsvg outputs into a larger SVG without regex-stripping wrappers.
Use Case
When embedding mdsvg output in larger SVG compositions, callers need to:
- Extract the inner content (currently requires regex)
- Know the actual rendered dimensions
Current workaround:
# Hacky regex extraction in dataface
content_svg = mdsvg.render(markdown, width=400)
inner_match = re.search(r"<svg[^>]*>(.*)</svg>", content_svg, re.DOTALL)
markdown_content = inner_match.group(1)
# Also need to extract height via regex
height_match = re.search(r'height="([0-9.]+)"', content_svg)
height = float(height_match.group(1))Proposed API
Option A: Structured result type
from mdsvg import render_content, RenderResult
result: RenderResult = render_content("# Hello", width=400)
result.content # SVG elements without <svg> wrapper
result.width # 400.0
result.height # Actual rendered height
result.to_svg() # Full SVG with wrapper (convenience method)Option B: Parameter to skip wrapper
# Returns just the inner content
content = render("# Hello", width=400, wrap=False)
# Separate function to get dimensions
dims = get_dimensions("# Hello", width=400)
dims.width, dims.heightRecommendation
Option A (structured result) is cleaner - it's the pattern we just implemented in dataface's LayoutResult and works well.
@cursor Instructions
- Create a
RenderResultdataclass withcontent,width,heightfields - Add
to_svg()method that wraps content in SVG element - Add
render_content()function that returnsRenderResult - Keep existing
render()function unchanged for backward compatibility - Add tests for the new API
- Update README with examples
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels