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

Fix document(HtmlTag) in TagCreator #188

Open
obecker opened this issue Jun 12, 2021 · 1 comment
Open

Fix document(HtmlTag) in TagCreator #188

obecker opened this issue Jun 12, 2021 · 1 comment

Comments

@obecker
Copy link
Contributor

obecker commented Jun 12, 2021

There is this method in TagCreator:

    public static String document(HtmlTag htmlTag) {
        return document().render() + htmlTag.render();
    }

This returns a String by calling render(), thus it prevents using the new render possibilities introduced with #179

A better approach would be if there is a Document class that implements Renderable and that handles the correct rendering.

Apparently this would break code written for j2html 1.*, so it is something we should consider for a 2.* release.

@ritzow
Copy link

ritzow commented Nov 30, 2021

That method is also inefficient given it renders the entire document and then does a string concatenation, duplicating the whole thing, instead of just writing to a StringBuilder, It could be updated to render to a shared StringBuilder and the unescaped text object doesn't even need to be created. But for version 2 I agree it should be its own type.

htmlTag.render(FlatHtml.inMemory(Config.global()).appendUnescapedText("<!DOCTYPE html>"), null);

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

No branches or pull requests

3 participants