tipsy / j2html

Java to HTML generator. Enjoy typesafe HTML generation.

Home Page:https://j2html.com/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

question for <code> tag

Suna-Wang opened this issue · comments

commented

I wrote a test case to test the code tag, the case is followed:

public void pre_code_test12() {
    String output = pre(
        code("#include &lt;iostream&gt;" +
            "void main(){" +
            "cout &lt;&lt; &quot;Hello!&quot; &lt;&lt; end1;" +
            "}")
    ).render();

}
What I expected is

#include <iostream>void main(){cout << "Hello!" << end1;}

But the output is

#include &lt;iostream&gt;void main(){cout &lt;&lt; &quot;Hello!&quot; &lt;&lt; end1;}

Then the output will be different from the real need.
expected:
#include void main(){cout << "Hello!" << end1;}
output:
#include <iostream>void main(){cout << "Hello!" << end1;}

How can I produce what I want?

@Suna-Wang j2html provides automatic text escaping in most cases. For your example you can use:
pre( code("#include <iostream>void main(){cout << "Hello!" << end1;}") ).render()

which will produce this html:
<pre><code>#include &lt;iostream&gt;void main(){cout &lt;&lt; &quot;Hello!&quot; &lt;&lt; end1;}</code></pre>

which the browser should render into the output you desired.

commented

Thank you very much!~