j2html icon indicating copy to clipboard operation
j2html copied to clipboard

Embedding SVG

Open dhsilber opened this issue 3 years ago • 1 comments

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.

dhsilber avatar Jun 28 '22 23:06 dhsilber

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>

sembler avatar Jun 29 '22 00:06 sembler