propensive / rapture

Rapture
183 stars 39 forks source link

<span/> is not valid HTML5 #107

Open larsrh opened 8 years ago

larsrh commented 8 years ago

@propensive, you said you wanted early adopters, so now you have to deal with these bug reports :wink:

scala> import rapture.html.htmlSyntax._
import rapture.html.htmlSyntax._

scala> Span("").format
res0: String = <span></span>  // this is correct

scala> import rapture.dom._
import rapture.dom._

scala> import rapture.html._
import rapture.html._

scala> List(): List[AppliedElement[Html5.Phrasing, Html5.Phrasing, AttributeType]]
res2: List[rapture.dom.AppliedElement[rapture.html.Html5.Phrasing,rapture.html.Html5.Phrasing,rapture.dom.AttributeType]] = List()

scala> Span(res2)
res3: rapture.dom.AppliedElement[rapture.html.Html5.Phrasing,rapture.html.Html5.Phrasing,rapture.dom.AttributeType] = <span/>

scala> res3.format
res4: String = <span/> // this is incorrect ... span isn't self-closing
larsrh commented 8 years ago

This might happen in more situations than outlined above ... my workaround to not construct Spans with an empty list doesn't prevent the problem.

propensive commented 8 years ago

Ah, this rule applies to a few elements which aren't self-closing. I've implemented it for some with forceClosingTag = true in the HTML syntax definitions, but not span.

I wonder if there's a list of non-self-closing tags in HTML5...

propensive commented 8 years ago

I think this is the relevant part of the HTML5 spec:

There are five different kinds of elements: void elements, raw text elements, escapable raw text elements, foreign elements, and normal elements.

Void elements area, base, br, col, embed, hr, img, input, keygen, link, meta, param, source, track, wbr Raw text elements script, style escapable raw text elements textarea, title Foreign elements Elements from the MathML namespace and the SVG namespace.

I think this means I should handle each type slightly differently, but the default should not be to self-close any tags.

mielientiev commented 8 years ago

Hi @propensive . I'm just starting to see into rapture internals and trying to fix this bug. Please correct me if I misunderstood something, default value of forceClosingTag should be true. All "Void elements" should be self closing (forceClosingTag = false)