fix: normalize font-family in XML attributes instead of escaping#38
Open
OmChillure wants to merge 1 commit into1jehuang:masterfrom
Open
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Issue :
When passing a configuration with quoted font names (e.g., "Inter", "ui-sans-serif", "system-ui", "-apple-system", "Segoe UI", sans-serif), SVG renderers like usvg fail to render any text in the diagram.
The previous fix attempted to
escape_xml the font-family, resulting in output like:
font-family=""Inter", "ui-sans-serif", ...".When an SVG parser (like usvg) reads this, it decodes " back to " and treats the entire comma-separated string as a single font name. It then fails to find a font named literally "Inter", "ui-sans-serif"... and skips rendering the text.
The Fix
Renamed normalize_font_family_css to normalize_font_family. This helper was already correctly removing quotes but was only being used in CSS <style> blocks.
Replaced
escape_xml(&theme.font_family)withnormalize_font_family(&theme.font_family)in all XML attribute contexts.Found and fixed several other locations where theme.font_family was being interpolated in raw form without any escaping/normalization.
Resulting Output
font-family="Inter, ui-sans-serif, system-ui, -apple-system, Segoe UI, sans-serif"Without the surrounding quotes on each font name, the XML structural integrity is maintained, and usvg can successfully parse the list and resolve the fallback fonts individually.
Testing
Verified all 136 cargo tests pass.
Rendered SVG via CLI with a heavily quoted font-family and confirmed clean output font-family="Inter, ui-sans-serif...".
CLI Testing
Rendered a simple diagram using a JSON config that passes the exact
fontFamilystring causing issues.Command run:
Result :
font-family="Inter, ui-sans-serif, system-ui, -apple-system, Segoe UI, sans-serif"The output confirmed that all double quotes surrounding individual font names were successfully stripped, leaving a clean, comma-separated list of fonts that usvg can parse.