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

Support SVG icon id attributes with single quotes in the styleguide #11903

Merged
merged 3 commits into from
May 30, 2024

Conversation

laymonage
Copy link
Member

@laymonage laymonage commented Apr 29, 2024

Fixes #11895. The HTML spec allows attributes to have no value, unquoted value, single-quoted value, and double-quoted value: https://html.spec.whatwg.org/multipage/syntax.html#attributes-2

This issue has been around since the styleguide's icon list was reimplemented as a table in 43ca8be. In the implementation, our regex only considers the most common use case (double-quoted value).

@@ -30,7 +30,7 @@ Draw or download an icon and save it in a template folder:

The `svg` tag should:

- Set the `id="icon-<name>"` attribute, icons are referenced by this name.
- Set the `id="icon-<name>"` attribute, icons are referenced by this `name`. The `name` should only contain lowercase letters, numbers, and hyphens.
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pretty sure this limitation only exists because of the styleguide's regex, and the icons can technically still be used elsewhere as long as the ID is prefixed with icon-. Alternatively we could update the regex to be more permissive.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think alphanumeric hyphenated should be fine? I’d be surprised if XML allowed much more.

Copy link
Member Author

@laymonage laymonage May 30, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it allows at least a few others (e.g. :, ., _) and of course, uppercase letters should have no issues
https://www.w3.org/TR/REC-xml/#NT-Name

But yeah I don't think we want to encourage people to use unconventional IDs as that may cause other unexpected issues down the line. (Uppercase letters might not be so controversial though)

Copy link

squash-labs bot commented Apr 29, 2024

Manage this branch in Squash

Test this branch here: https://laymonagefix-styleguide-icon-q-6wvk1.squash.io

@gasman
Copy link
Collaborator

gasman commented Apr 29, 2024

Bumping to 6.2, since at this point any new additions to 6.1 should only really be regressions and critical issues (to minimise the possibility of introducing new issues that haven't been tested with a release candidate).

@gasman gasman modified the milestones: 6.1, 6.2 Apr 29, 2024
Copy link
Member

@thibaudcolas thibaudcolas left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM aside from the "no quotes" support! I’ll remove it as we discussed and merge.

@@ -30,7 +30,7 @@ Draw or download an icon and save it in a template folder:

The `svg` tag should:

- Set the `id="icon-<name>"` attribute, icons are referenced by this name.
- Set the `id="icon-<name>"` attribute, icons are referenced by this `name`. The `name` should only contain lowercase letters, numbers, and hyphens.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think alphanumeric hyphenated should be fine? I’d be surprised if XML allowed much more.

# Allow no quotes, single quotes, and double quotes for the ID.
# For simplicity and readability, we don't enforce the opening
# and closing quotes to match.
icon_id_pattern = re.compile(r"""id=["']?icon-([a-z0-9-]+)["']?""")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should drop the "no quotes" option, as it’s apparently invalid in XML – see the AttValue parsing.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right, I forgot SVG is XML and not HTML!

thibaudcolas added a commit to laymonage/wagtail that referenced this pull request May 30, 2024
@thibaudcolas thibaudcolas changed the title Allow icons with unquoted/single-quoted ids in the styleguide Support SVG icon id attributes with single quotes in the styleguide May 30, 2024
@thibaudcolas thibaudcolas merged commit 157a06d into wagtail:main May 30, 2024
0 of 15 checks passed
thibaudcolas added a commit that referenced this pull request May 30, 2024
…11903)

Co-authored-by: Thibaud Colas <thibaudcolas@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
Status: ✅ Done
Development

Successfully merging this pull request may close these issues.

styleguide - custom icons with id defined with single quotes cause 500 error when loading style guide
3 participants