chinedufn / percy

Build frontend browser apps with Rust + WebAssembly. Supports server side rendering.
https://chinedufn.github.io/percy/
Apache License 2.0
2.26k stars 84 forks source link

Rust keywords in attribute list #130

Closed FinnStokes closed 5 years ago

FinnStokes commented 5 years ago

When compiling a HTML form containing labels with for attributes, I get the error

error: expected `>`
  --> app/src/views/login.rs:18:24
   |
18 |                 <label for="username">Username:</label>
   |                        ^^^

error: aborting due to previous error

My current workaround is to use capitalisation to avoid the parser treating the attribute as a keyword (since Rust is case sensitive and HTML is not). For example:

<label For="username">Username:</label>

There are four Rust keywords that are also valid HTML attributes: async, for, loop, and type. There already seems to be special handling for type in parse_attributes: https://github.com/chinedufn/percy/blob/66e1dcd4ed94733160ec694dfcb2021be3d7503a/crates/html-macro/src/tag.rs#L131-L144

I think the remaining three keywords just need to be added there. I will create a pull request for this change.

chinedufn commented 5 years ago

Thanks for opening this very thorough issue!