j2html
j2html copied to clipboard
Embedding SVG
How can one embed SVG into a j2html-generated document?
I am already building my SVG with Apache's batik-svggen project which has the SVG in a DOM implementation and can generate appropriate text. I would like to be able to wrap my existing generated SVG in an HTML document.
My apologies if this is documented somewhere, but I haven't been able to find any way to do so.
This should be possible using the TagCreator.rawHtml(String html) method. It will take whatever string you give it and append it directly to the output when it is rendered. Example:
J2html
html(
body(
rawHtml(
"<svg>\n" +
" <rect width=\"300\" height=\"100\"/> \n" +
"</svg>"
)
)
);
Rendered Html
<html>
<body>
<svg>
<rect width="300" height="100"/>
</svg>
</body>
</html>