lambda-fairy / maud

:pencil: Compile-time HTML templates for Rust
https://maud.lambda.xyz
Apache License 2.0
1.98k stars 132 forks source link

emit short tag on empty blocks #341

Closed HookedBehemoth closed 2 years ago

HookedBehemoth commented 2 years ago

This changes the emited markup with tags like this: use href="#page" {} from <use href="#page"></use> to <use href="#page"/>. Other tags this is useful for are e.g. video and all svg subtags.

zr40 commented 2 years ago

Unfortunately <foo/> is not correct according to the spec:

Start tags consist of the following parts, in exactly the following order:

  1. A "<" character.
  2. The element’s tag name.
  3. Optionally, one or more attributes, each of which must be preceded by one or more space characters.
  4. Optionally, one or more space characters.
  5. Optionally, a "/" character, which may be present only if the element is a void element.
  6. A ">" character.

The optional / character has no significance to HTML parsers, so it does not have the effect you desire. For instance, <div/><div/> is equivalent to <div><div>.

For void elements, those that do not require a closing tag, you can use ; instead of {}.

HookedBehemoth commented 2 years ago

Thanks for letting me know. Came from xmpp and just assumed this would be XML standard.

lambda-fairy commented 2 years ago

I have a pending feature request for XML support at #62. It's a bit more complicated than it looks because of 🅰️ context-aware escaping and 🅱️ namespaces.