fix(export): escape ampersands in the injected font import (#38)

A standalone SVG is parsed as strict XML where a bare ampersand is a fatal entity error. Escaping is valid in both SVG and HTML. Fixes #37.
This commit is contained in:
kabire2014-eng
2026-08-12 21:50:09 -07:00
committed by GitHub
parent 2e2b45e7c9
commit f928399e20
+2 -2
View File
@@ -32,10 +32,10 @@ If the user explicitly asks for "a screenshot of the whole page including the ca
- Ensure the opening tag has `xmlns="http://www.w3.org/2000/svg"`. Add it if missing. - Ensure the opening tag has `xmlns="http://www.w3.org/2000/svg"`. Add it if missing.
- Ensure a `viewBox` is present. The skill's templates always include one; warn the user if absent rather than guessing. - Ensure a `viewBox` is present. The skill's templates always include one; warn the user if absent rather than guessing.
- Preserve `role="img"`, `aria-labelledby`, and the first-child `<title>` / `<desc>` exactly as authored. - Preserve `role="img"`, `aria-labelledby`, and the first-child `<title>` / `<desc>` exactly as authored.
- Inject Google Fonts `@import` so the SVG renders with correct typography in a browser: - Inject Google Fonts `@import` so the SVG renders with correct typography in a browser. **XML-escape the `&` separators as `&amp;`** — a standalone `.svg` is parsed as strict XML, where a bare `&` starts an entity reference and makes the whole file fail to parse. (Don't copy the raw URL from the HTML `<link href>`; that ampersand form is only valid in HTML.)
```svg ```svg
<defs> <defs>
<style>@import url('https://fonts.googleapis.com/css2?family=Instrument+Serif:ital@0;1&family=Geist:wght@400;500;600&family=Geist+Mono:wght@400;500;600&display=swap');</style> <style>@import url('https://fonts.googleapis.com/css2?family=Instrument+Serif:ital@0;1&amp;family=Geist:wght@400;500;600&amp;family=Geist+Mono:wght@400;500;600&amp;display=swap');</style>
</defs> </defs>
``` ```
If the SVG already contains a `<defs>` block, **merge** the `<style>` into it (don't add a second `<defs>`). If the SVG already contains a `<defs>` block, **merge** the `<style>` into it (don't add a second `<defs>`).