Example DSL for writing html in Java. Rework of benjiman/java-html-dsl to work with newer versions of Java
This
Stringdoc =
html(
head(
title("Hello Html World"),
meta($ -> $.charset = "utf-8"),
link($->{ $.rel=stylesheet; $.type=css; $.href="/foo.css"; }),
script($->{ $.type= javascript; $.src="/some.js"; })
),
body(
div($-> $.cssClass = "article",
a($-> $.href="https://benjiweber.com/",
span($->$.cssClass="label", "Click Here"),
img($->{$.src="/myimg.jpg"; $.width=px(25); $.height=px(25); })
),
p(span("some text"), div("block"))
)
)
).formatted()Generates
<html><head><title>Hello Html World</title><metacharset="utf-8" /><linkrel="stylesheet" type="css" href="/my.css" /><scripttype="text/javascript" src="/some.js" ></script></head><body><divclass="article"><ahref="https://benjiweber.com/"><spanclass="label">Click Here</span><imgsrc="/myimg.jpg" width="25" height="25" /></a><p><span>some text</span><div>block</div></p></div></body></html>