tipsy / j2html

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

render quote ? #100

Closed Reekoj closed 6 years ago

Reekoj commented 6 years ago

Hello, it's kind of a noob question but i can't find a way to render the quote symbol ? for example if i do that : script("alert(\"hello world\");").withType("text/javascript") the string rendered look like that : <script type="text/javascript">alert(&quot;hello world&quot;);</script>

tipsy commented 6 years ago

All text is escaped by default (to prevent XSS). You can use therawHtml() method:

script(rawHtml("alert(\"hello world\");")).withType("text/javascript"), but I'd probably flip it for readability:

script().withType("text/javascript").with(
    rawHtml("alert('hello world');")
), 
Reekoj commented 6 years ago

Ok it works, Thanks for the help (and for j2html btw that's great)

tipsy commented 6 years ago

You're welcome (and thanks!)

Reekoj commented 6 years ago

Oh and i wanted to ask you something, sorry that's not related to this issue but i'm wondering why you say on your website that we shouldn't use j2html with Bootstrap ? because i tried with a simple w3school's example and it works http://prntscr.com/hylr61

tipsy commented 6 years ago

@Reekoj it's fine if you want to do that, but Bootstrap has very verbose markup (a lot of lines of HTML per component). Normally you would just copy-paste the HTML from the bootstrap site, but you'll have to convert everything to j2html-code if you want to use it with j2html. If you use a template engine instead, you can just copy-paste the HTML directly into the template.