Vitor Baptista
Vitor Baptista

Reputation: 2096

How to mix text and HTML tags inside <pre> with Jade without removing newlines?

I would like the generated HTML to be:

<!DOCTYPE html>
<html>
  <head></head>
  <body>
    <pre>First line
<em>Second line</em>
Third line</pre>
  </body>
</html>

I tried using:

doctype html
html
  head
  body
    pre.
      First line
      em second line
      third line

But it doesn't work, because pre. considers everything under it to be text. So I tried removing it and using | instead, as in:

doctype html
html
  head
  body
    pre
      | First line
      em second line
      | third line

But this puts everything inside the pre on a single line, as in:

<!DOCTYPE html>
<html>
  <head></head>
  <body>
    <pre>First line<em>second line</em>third line</pre>
  </body>
</html>

Which is not what I want. As far as I can see, my only option is to embed HTML in Jade, as in:

doctype html
html
  head
  body
    pre.
      First line
      <em>second line</em>
      third line

Is there another way?

Upvotes: 0

Views: 698

Answers (1)

laggingreflex
laggingreflex

Reputation: 34677

You want escaped HTML

pre.
    First line
    &lt;em&gt;second line&lt;/em&gt;
    third line

or with the use of #{} :

pre.
    First line
    #{"<em>second line</em>"}
    third line

Upvotes: 1

Related Questions