byteface / domonic

Create HTML with python 3 using a standard DOM API. Includes a python port of JavaScript for interoperability and tons of other cool features. A fast prototyping library.
https://domonic.readthedocs.io/
MIT License
131 stars 13 forks source link

feature request: boolean attributes #40

Closed kthy closed 3 years ago

kthy commented 3 years ago

In HTML5, there are a number of boolean attributes, e.g. async, checked and disabled. It would be nice if these could be recognized and simply output as their short form. Currently, as a workaround, you can give them an empty string or their own name as value, e.g.

_script(_src="foo.js", _async="async")

gives

<script src="foo.js" async="async"/>

but would be nice if we could have

<script src="foo.js" async/>
byteface commented 3 years ago

i remember about a year ago thinking about and looking into this for a few hours. can't remember what i did about it. I think I gave up. but calling the same name or empty for those attrs is a good idea.

you think a few cheeky classes in the namespace i.e async, checked, disabled_ may also work as additional?. how many does it apply to . all attributes? or just a small handful? I will investigate this a get back to you soon. It's a good one.

byteface commented 3 years ago

ignore my namespace idea. i think yours is better. empty for me would be most natural thing to do.

byteface commented 3 years ago

it actually ties in though to a bigger thought process. about being able to configure the default behaviour. I've been thinking for a whlie about some config settings for domonic. so that you could flag it do do certain types of output. i.e. so a flag to auto do that for you. that's on by default.

byteface commented 3 years ago

with such a config you could omit closing tags on lists for example and do cool html5 things.