[ANN] dream-html 3.0.0

Hi, dream-html 3.0.0 has been released to opam: dream-html 3.0.0 · OCaml Package

Repo: GitHub - yawaramin/dream-html: Generate HTML markup from your OCaml Dream backend server
API docs: Dream_html (dream-html.Dream_html)

Dream-html is a library for generating HTML, closely integrated with Dream. It can be used as an alternative to Dream’s built-in Embedded ML templating language and comes with all current htmx attributes defined out of the box.

In this release, I made a breaking change (hence major version bump) to restrict the role attribute to only the acceptable values for ARIA roles. Previously it was accepting any format string.

Plus a major new feature: all the ARIA attributes with the types of their values narrowed as much as possible. Eg:

open Dream_html
open HTML

let toast ?(idval="toast") msg =
  p [id "%s" idval; Aria.live `polite; Hx.swap_oob "true"] [txt "%s" msg]
10 Likes

I’ve just released 3.0.1 with a bugfix for ARIA attribute names, please upgrade if you are using ARIA: dream-html 3.0.1 · OCaml Package

1 Like

I have converted my server to it… quite easy (any typing error is sanctionned by the OCaml compiler instead of silencely served to the client.).

Is the Dream — Tidy, feature-complete web framework page upgrade in progress ? I may also propose something, but prefer to have guidelines before working in a direction which won’t be approved.

Hi, thank you for trying it. I have not proposed anything to the Dream maintainer as I believe he prefers the Embedded ML template engine. Hence dream-html is strictly an alternative option.

EDIT: if you are interested in contributing to Dream I would suggest that the number 1 priority is to port it over to OCaml 5 (Multicore) and Eio to make it run multi-threaded. There is an open PR attempting it now. I have also been thinking of another approach, DM me if you are interested.

[ANN] dream-html 3.1.0

Thanks to the efforts of Kento Okura, I am happy to announce the release of 3.1.0, which brings complete support for all standard MathML attributes and elements.

Eg:

open Dream_html
open MathML

let op sym = mo [] [txt "%s" sym]

let pow i n = msup [] [
  mi [] [txt "%s" i];
  mn [] [txt "%s" n];
]

(* a^2+b^2=c^2 *)
let pythagoras_theorem = mtable [] [
  mtr [] [
    mtd [] [pow "a" "2"; op "+"; pow "b" "2"];
    mtd [] [op "="];
    mtd [] [pow "c" "2"];
  ];
]

As you can see, we can write helpers that greatly reduce duplication.

This addition completes dream-html’s support for all standard XML-based markups that are rendered by browsers.

This release also deprecates a couple of non-standard HTML attributes that I had mistakenly added before.

6 Likes

[ANN] dream-html 3.2.0

Thanks to Marco Schneider for noticing and adding a missing convenience wrapper for Dream.send, now we have Dream_html.send to write markup directly to a WebSocket as text.

Also a change to use our internal function to escape the text inside HTML comments ie comment "xyz".

1 Like

[ANN] dream-html 3.3.1

Add to_xml and pp_xml functions to render in XML style

Normally, dream-html defaults to rendering nodes in HTML style, meaning that void elements are rendered just like opening tags. Eg <br>. With the new to_xml and pp_xml functions, we can now render nodes in XML style, meaning <br />. This allows XML parsers to successfully parse the output. So eg you can use dream-html to author an ePub book.

Escape URI attributes like href with normal attribute escaping rules in addition to percent-encoding. Most significantly, ampersands are encoded now, eg /foo?a=1&b=2 is rendered as /foo?a=1&amp;b=2.

Change where line breaks are inserted into the output markup, so that there is no chance of injecting spurious whitespace into the rendered page. This gives complete control over whitespace to the user.

5 Likes

[ANN] dream-html 3.4.1

Add ‘livereload’ support ie automatically reloading the page in the browser when the Dream server restarts. Useful to run with dune’s watch mode for a fast dev cycle.

This is adapted from Dream’s own livereload middleware but with a slightly different approach. Full details in the module documentation: Livereload (dream-html.Dream_html.Livereload)

Why reimplement this? It seems that Dream’s built-in livereload needs to parse the HTML markup, find its head tag, and dynamically inject the reloader script inside. Since parsing HTML can be pretty tricky and potentially buggy, I decided to manually add the script in the head tag as a strong-typed dream-html node:

head [] [
  ...
  Livereload.script;
  ...
]
3 Likes