Skip to content

Enhancement: Select the minimum length format for strings #882

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

Open
2 tasks
mcandre opened this issue Dec 29, 2017 · 1 comment
Open
2 tasks

Enhancement: Select the minimum length format for strings #882

mcandre opened this issue Dec 29, 2017 · 1 comment
Assignees

Comments

@mcandre
Copy link

mcandre commented Dec 29, 2017

To further shrink SVG content, we can select string literal formats tailored to reduce the number of escape characters involved, for each individual string constant. E.g., '"' is preferable to "\"", and "'" is preferable to '\''.

  • For each string constant, compare how the constant would be quote-escaped in double- vs. single-quoted formatted literals.
  • Select the minimal length format for that particular string constant and emit to output.
@SethFalco SethFalco self-assigned this Dec 2, 2023
@SethFalco
Copy link
Member

SethFalco commented Dec 2, 2023

This is interesting, I'm assuming this mostly applies to attribute values. Overall, it looks like we don't need to encode quot/apos entities if they're used in the other kind of quote.

On MDN, we can see various SVGs use different kinds of quotes for attribute values.

See: https://developer.mozilla.org/en-US/docs/Web/SVG/Element/svg

On W3's SVG 1.1 validator, the following SVG passes, no need to encode XML entities:

<!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" >
<title>uwu</title>
<a xlink:href="uwu'owo"/>
<a xlink:href='uwu"owo'/>
</svg>

See: https://validator.w3.org/check

Assuming there are no consequences of this, we could achieve this by updating the types of of attrStart and attrEnd to be string | ((value: string) => string) and use one based on what would be smaller. This also preserved backward compatibility.

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

No branches or pull requests

2 participants