haskellblaze-html

Blaze Templating - Attribute with no value


Using Blaze, how can I write an attribute with no value? As in an attribute that's just one string, with no =.

For example, I want to add a YouTube embed in Blaze, but I don't know how to add the allowfullscreen part. The blaze-from-html tool just errors out and tells me that it's illegal in HTML5, and I'm not sure how to do it from the documentation. Here's how the HTML should look:

<iframe width="560" height="315"
    src="https://www.youtube.com/embed/T4r91mc8pbo" 
    frameborder="0" allowfullscreen>
</iframe>

I've tried creating a custom element like

allowfullscreen :: AttributeValue -> Attribute
allowfullscreen = attribute "allowfullscreen" " allowfullscreen"

but it appends the equal sign anyway - allowfullscreen"=" and full screen is disallowed.

I'm using blaze-html 0.8.1.1 and blaze-markup 0.7.0.3.


Solution

  • Boolean attributes (HTML5 spec)

    If the attribute is present, its value must either be the empty string or a value that is an ASCII case-insensitive match for the attribute’s canonical name, with no leading or trailing white space.

    Examples

    <label><input type=checkbox checked name=cheese disabled> Cheese</label>
    <label><input type=checkbox checked=checked name=cheese disabled=disabled> Cheese</label>
    <label><input type='checkbox' checked name=cheese disabled=""> Cheese</label>
    

    See also HTML4.

    There is a Github issue for blaze-html about that.

    So allowfullscreen="allowfullscreen" should work.