borkdude / html

Html generation library inspired by squint's html tag
MIT License
48 stars 1 forks source link

Web Standards #4

Closed darkleaf closed 3 months ago

darkleaf commented 3 months ago

I expect this code will return a valid html. And I don't care about which standard it will use.

#html
[:<>
   [:$ "<!DOCTYPE html>"]
   [:html {:lang "en"}
    [:head
     [:title "Hi"]]
    [:body
     [:div "ok"]
     [:br]]]]

HTML5 has void elements.

#html [:br] 

So in HTML5 it should return <br>, but now it returns <br></br>.

But there is XHTML and current implementation returns valid html.

I need an example how to use it with ring and render a valid html. Like this:

(defn- handler [req]
  (-> (ring.resp/ok
       (str #html
            [:<>
             [:$ "<?xml version=\"1.0\" encoding=\"UTF-8\"?>"]
             [:html {:xmlns "http://www.w3.org/1999/xhtml" :lang "en"}
              [:head
               [:title "Hi"]]
              [:body
               [:div "ok"]
               [:br]]]]))
      (ring.resp/content-type "application/xhtml+xml")))

I want #html to support only one standard, not like hiccup.

borkdude commented 3 months ago

I want #html to support only one standard, not like hiccup.

I'd vote for HTML5 but I think it would be nice to support other versions of HTML as well, if necessary. Not sure how (as options to the first element maybe) but let's leave that out of scope for now.

I need an example how to use it with ring and render a valid html.

What about your example doesn't yet work?

borkdude commented 3 months ago

I'm actually doubting if html5 is the better default over xhtml now since xhtml also can be used to generate XML

borkdude commented 3 months ago

I found out that this is valid XHTML 1.1:

(println
 (str
  (html
   [:<>
    [:$ "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.1//EN\" \"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd\">"]
    [:html {:xmlns "http://www.w3.org/1999/xhtml" :lang "en"}
     [:head
      [:meta {:http-equiv "Content-Type"
              :content "text/html; charset=utf-8"}]
      [:title "Hi"]]
     [:body
      [:div "ok"]
      [:p
       "yes"
       [:br]]]]])))
borkdude commented 3 months ago

Added the example to the README. Closing this for now. Until someone harasses me about HTML5 :)

darkleaf commented 3 months ago

Awesome! Let's use XHTML5

borkdude commented 3 months ago

After some more searching, I found the following evidence which maybe points to HTML5 in favor of XHTML(5).

In 2009, the W3C allowed the XHTML 2.0 Working Group's charter to expire, acknowledging that HTML5 would be the sole next-generation HTML standard, including both XML and non-XML serializations

You can search in the XHTML 1.1 schema for new html elements like article or section and you'll see that it's not there. You can contrast that with the HTML5 spec where you'll find many new elements not present in the XHTML spec.

That said, there's now "XHTML5" which is an XML-serialization of HTML5, which is just HTML5 with XML formatting and a different Content-Type header, essentially. More on that here: https://html.spec.whatwg.org/multipage/xhtml.html#xhtml -- but if you open that link you'll see this warning from the spec:

Using the XML syntax is not recommended, for reasons which include the fact that there is no specification which defines the rules for how an XML parser must map a string of bytes or characters into a Document object, as well as the fact that the XML syntax is essentially unmaintained — in that, it’s not expected that any further features will ever be added to the XML syntax (even when such features have been added to the HTML syntax).

Given this evidence, I'd say let's go with HTML5 then.

This information was provided by @corasaurus-hex on Slack

borkdude commented 3 months ago

Alright, I settled on HTML5 now.

New docs: https://github.com/borkdude/html?tab=readme-ov-file#complete-document

If people really want XML, there could be an xml macro, without any dynamic var stuff involved, but I'll wait for this to come up which might never be.