Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Embedding SVG #212

Open
dhsilber opened this issue Jun 28, 2022 · 1 comment
Open

Embedding SVG #212

dhsilber opened this issue Jun 28, 2022 · 1 comment
Labels

Comments

@dhsilber
Copy link

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.

@sembler
Copy link
Collaborator

sembler commented Jun 29, 2022

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>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants