tipsy / j2html

Java to HTML generator. Enjoy typesafe HTML generation.
https://j2html.com/
Apache License 2.0
765 stars 136 forks source link

<!DOCTYPE html/> when Config.closeEmptyTags=true #80

Closed kicktipp closed 7 years ago

kicktipp commented 7 years ago

This test fails.

import static j2html.TagCreator.document;
import static org.junit.Assert.assertEquals;
import org.junit.Test;
import j2html.Config;

public class DoctypeTest
{
    @Test
    public void test ( )
    {
        Config.closeEmptyTags = true;
        assertEquals("<!DOCTYPE html>", document().render());
    }
}

Fix:

public static RawHtml document()     { return new RawHtml("<!DOCTYPE html>"); }

public static String document(ContainerTag htmlTag) {
        if (htmlTag.getTagName().equals("html")) {
            return document().render() + htmlTag.render();
        }
        throw new IllegalArgumentException("Only HTML-tag can follow document declaration");
    }
tipsy commented 7 years ago

Thanks. Want to create a PR?

tipsy commented 7 years ago

Merged.

tipsy commented 6 years ago

Released as part of 1.2.1

<dependency>
    <groupId>com.j2html</groupId>
    <artifactId>j2html</artifactId>
    <version>1.2.1</version>
</dependency>

http://search.maven.org/#artifactdetails%7Ccom.j2html%7Cj2html%7C1.2.1%7Cjar