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
128 stars 13 forks source link

Omit end tag on empty elements #39

Closed kthy closed 2 years ago

kthy commented 2 years ago

This fixes #37. I think.

byteface commented 2 years ago

wow. very clever. that's actually pretty cool. I had wondered quite how those work. I've seen them in black formatted code.

funnily i've seen them in js too using && as the if check.

I stared at it for 4 mins and the penny finally dropped. That's really helpful to teach me if it's doing what i think it is.

i'll approve and run now. but release may have to wait until tonight. thanks so much btw

byteface commented 2 years ago

hmm. i think as the p tag has no content it will need a different check. let me have a look this evening and see. it was still helpful push as taught me the 'and' trick

byteface commented 2 years ago

so i have noticed the html package has bug as there's 2 meta tags. the top one must get overridden by the 2nd lower down.

the 2nd one correctly extend closed_tag. so if we use type to figure out if self is a closed tag, that might work.

kthy commented 2 years ago

I'm having the same issue with the script tag, which of course can also have content so not quite the same issue. :wink: You might want to mull this over a bit instead of just accepting my hot take! :grin:

byteface commented 2 years ago

ah of course. closed_tag would need it's own __format__ dunder! tag only got that last week. I bet that's why.