com-lihaoyi / cask

Cask: a Scala HTTP micro-framework. Cask makes it easy to set up a website, backend server, or REST API using Scala
https://com-lihaoyi.github.io/cask/
Other
525 stars 55 forks source link

Attributes with an empty value are wrongly generated. #102

Closed jrlemieux closed 8 months ago

jrlemieux commented 8 months ago

I create an attribute autoplay with:

 scalatags.generic.Attr("autoplay").empty

If I use it in a tag, the generated tag will contain the attribute specification autoplay="autoplay" instead of autoplay. There are many HTML attributes that must be specified as an identifier only, rather than as an identifier+value pair.

I think that this line:

def empty[Builder](implicit ev: AttrValue[Builder, String]) = this := name

Could be replaced by:

def empty[Builder](implicit ev: AttrValue[Builder, String]) = this := null

and null should be an acceptable value for the value field. When the attribute is generated, the null value could be used a hint that only the identifier must be generated rather than a key/value pair.

Thank you.

lihaoyi commented 8 months ago

This is probably working as intended. Boolean attributes are allowed to be rendered as foo="foo":

https://www.w3.org/TR/REC-html40/intro/sgmltut.html#h-3.3.4.2

Although not all user agents support the "expanded" foo="foo" syntax for boolean attributes, most do. Is there a specific browser which this is causing problems for you?