fix: extract inline CSS styles to native SVG attributes for GitHub compatibility#47
Conversation
…mpatibility GitHub's SVG sanitizer strips inline style attributes, which removes all stroke, fill, and font properties. This causes lines, relationship arrows, package borders, and component separators to disappear when SVGs are rendered on GitHub. SvgStyleExtractor converts CSS style properties (stroke, stroke-width, stroke-dasharray, fill, font-*) to native SVG presentation attributes that GitHub preserves. Non-convertible CSS properties (transform, background) remain in the style attribute. Bump version to 3.9.1. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 6f8d642591
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| for (Map.Entry<String, String> e : converted.entrySet()) { | ||
| replacement.append(' ').append(e.getKey()).append("=\"").append(e.getValue()).append('"'); | ||
| } |
There was a problem hiding this comment.
Avoid emitting duplicate SVG attributes during style extraction
When a node already has a native attribute (for example fill="#fff") and its style also contains the same property (fill:#000), this loop blindly appends another fill/stroke/font-* attribute, producing duplicate attribute names on one element. Duplicate attributes make the SVG not well-formed XML and can cause renderers/sanitizers (including GitHub’s pipeline) to reject or misrender the element, which defeats the compatibility fix for any embedded SVGs that mix presentation attributes and inline style.
Useful? React with 👍 / 👎.
Avoid emitting duplicate attributes when an element already has a native attribute (e.g. fill="#fff") and the inline style also declares the same property. The extractor now matches the full opening tag to detect existing native attributes and skips conversion for those properties. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Summary
styleattributes from embedded SVGs, causing all strokes (package borders, relationship arrows, component separator lines) to disappear when striffs are rendered on GitHubSvgStyleExtractorpost-processor that converts CSSstyleproperties (stroke,stroke-width,stroke-dasharray,fill,font-*, etc.) to native SVG presentation attributes that GitHub preservestransform,background) remain in thestyleattributeTest plan
SvgStyleExtractorcovering stroke conversion, dash arrays, mixed convertible/non-convertible, pass-through, font properties, and existing attribute preservationmvn verifypasses (189 tests, 0 checkstyle violations, 0 PMD violations)🤖 Generated with Claude Code