-
Notifications
You must be signed in to change notification settings - Fork 1
Open
Description
Summary
Add a text_align option to the Style class to control horizontal text alignment.
Use Case
When embedding mdsvg output in larger SVG compositions (like dashboards), callers often need to align text. Currently this requires hacky string manipulation:
# Current workaround in dataface
aligned_title = title_svg.replace("<text", f'<text text-anchor="{title_anchor}"')Proposed API
from mdsvg import Style, render
# Option 1: Style parameter
style = Style(text_align="center") # "left", "center", "right"
svg = render("# Title", style=style)
# Option 2: Render parameter
svg = render("# Title", text_align="center")Implementation Notes
- Map
text_alignto SVGtext-anchorattribute:"left"→text-anchor="start""center"→text-anchor="middle""right"→text-anchor="end"
- Apply to all
<text>elements in the output - Default to
"left"(current behavior)
@cursor Instructions
- Add
text_align: str = "left"to theStyleclass - In the SVGRenderer, apply
text-anchorattribute based on text_align value - Add tests for left/center/right alignment
- Update README with example
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels