10

I am converting my html rendering code to use j2html. Whilst I like the library it is not easy for me to convert all the code in one go so sometimes I may convert the outer html to use j2html but not able to convert the inner html to j2html at the same time. So I would like j2html to be able to accept text passed to it as already rendered, but it always re-renders it so

System.out.println(p("<b>the bridge</b>"));

returns

<p>&lt;b&gt;the bridge&lt;/b&gt;</p>

is there a way I get it to output

<p><b>the bridge</b></p>

Full Test Case

import j2html.tags.Text;

import static j2html.TagCreator.b;
import static j2html.TagCreator.p;

public class HtmlTest
{
    public static void main(String[] args)
    {
        System.out.println(p(b("the bridge")));
        System.out.println(p("<b>the bridge</b>"));
    }

}
Paul Taylor
  • 13,411
  • 42
  • 184
  • 351

2 Answers2

5
import static j2html.TagCreator.b;
import static j2html.TagCreator.p;
import static j2html.TagCreator.rawHtml;


public class HtmlTest
{
    public static void main(String[] args)
    {
        System.out.println(p(b("the bridge")));
        System.out.println(p(rawHtml("<b>the bridge</b>")));
    }

}

Result:

<p><b>the bridge</b></p>
<p><b>the bridge</b></p>
selten98
  • 821
  • 4
  • 15
  • This maybe a route to a right answer but you have omitted it being wrapped within a paragraph so cant tell. – Paul Taylor Jun 22 '17 at 20:01
  • Never saw that, I think the issue is there is no javadoc for this project (is there ?) so I was just relying on examples, thanks alot. – Paul Taylor Jun 22 '17 at 20:48
  • @PaulTaylor I looked into the code (TagCreator.java) it was in there. That's how I found it. I'm not sure if it is in the documentation. – selten98 Jun 22 '17 at 20:48
1

In j2html 1.1.0 you can disable text-escaping by writing

Config.textEscaper = text -> text;

Be careful though..

tipsy
  • 402
  • 4
  • 15