Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

devvit create icons doesn't strip xml preamble #128

Open
PitchforkAssistant opened this issue Dec 14, 2024 · 0 comments
Open

devvit create icons doesn't strip xml preamble #128

PitchforkAssistant opened this issue Dec 14, 2024 · 0 comments

Comments

@PitchforkAssistant
Copy link
Contributor

devvit create icons is supposed to convert svg files in the assets folder into usable image strings. That process results in an invalid svg if the file contains anything ahead of the <svg> tag.

The average svgfile will look something like this:

<?xml version="1.0" standalone="no"?>
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd" >
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" version="1.1" viewBox="0 0 300 300">
    <rect x="0" y="0" width="300" height="300" fill="red" />
</svg>

or this:

<?xml version="1.0" encoding="UTF-8"?>
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 300 300">
    <rect x="0" y="0" width="300" height="300" fill="red" />
</svg>

In both examples, the data before the actual svg is retained in the output, resulting in something like this:

import {svg} from "@devvit/public-api";

export const Icons = {
  "exampleOne.svg": svg`<?xml version="1.0" standalone="no"?><!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd" ><svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" version="1.1" viewBox="0 0 300 300">    <rect x="0" y="0" width="300" height="300" fill="red" /></svg>`,
  "exampleTwo.svg": svg`<?xml version="1.0" encoding="UTF-8"?><svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 300 300">    <rect x="0" y="0" width="300" height="300" fill="red" /></svg>`,
} as const;

That results in the svg helper function logging "The provided string is not a valid SVG." and returning an empty string. Either the devvit create icons command or svg function needs to account for this, otherwise there is a lot of manual work required each time you regenerate the icons.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

1 participant