Skip to content

Latest commit

History

5 Commits

Folders and files

NameName
Last commit message
Last commit date

Repository files navigation

java-html-dsl

This won't work in newer versions of Java where parameter name reflection was removed. See https://github.com/benjiman/java-html-dsl2 for another approach.

DSL for writing html in Java http://benjiweber.co.uk/blog/2015/08/21/html-in-java

This

Stringdoc =
html(
head(
meta(charset -> "utf-8"),
link(rel->stylesheet, type->css, href->"/my.css"),
script(type->javascript, src -> "/some.js")
),
body(
h1("Hello World", style->"font-size:200%;"),
article(
p("Here is an interesting paragraph"),
p(
"And another",
small("small")
),
ul(
li("An"),
li("unordered"),
li("list")
)
)
)
).asString();

Generates

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN"><html><head><metaname="generator" content=
"HTML Tidy for Java (vers. 2009-12-01), see jtidy.sourceforge.net"><metacharset="utf-8"><scripttype="text/javascript" src=
"/some.js"></script><title></title></head><body><h1>Hello World</h1><p>Here is an interesting paragraph</p><p>And another<small>small</small></p><ul><li>An</li><li>unordered</li><li>list</li></ul></body></html>

About

DSL for writing HTML in Java

Resources

Stars

67 stars

Watchers

5 watching

Forks

Releases

Packages

Used by

Contributors

Languages