Skip to content

Some node names that include numbers are not parsed #43

@gbj

Description

@gbj

Per the HTML spec, an attribute name like data-id-25 is valid (albeit maybe unusual)

Attribute names must consist of one or more characters other than the space characters, U+0000 NULL, U+0022 QUOTATION MARK ("), U+0027 APOSTROPHE ('), U+003E GREATER-THAN SIGN (>), U+002F SOLIDUS (/), and U+003D EQUALS SIGN (=) characters, the control characters, and any characters that are not defined by Unicode. link

This can't be parsed by syn-rsx at present because each segment of the node name needs to be an Ident, and 25 isn't a valid Rust identifier.

You're probably more familiar with syn than I am but I wonder if changing the Punctuated variant of NodeName to something like

Punctuated(Punctuated<NodeNameFragment, Punct>),

where

pub enum NodeNameFragment {
  Ident(Ident),
  Number(u32)
}

would be a possibility. This only expands the possibilities to include numbers, and not other possibly-valid attribute names that aren't valid Rust identifiers, but would be a start.

Here's an issue in my repo with an example of where someone would use it—using a class: syntax to toggle a Tailwind-like CSS class name that included a number after a dash.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions