如何在不删除换行符的情况下将 <pre> 内的文本和 HTML 标签与 Jade 混合?

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

我希望生成的 HTML 是:

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

我尝试使用:

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

但它不起作用,因为 pre. 认为它下面的所有内容都是文本。所以我尝试删除它并使用 | 代替,如:

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

但这会将 pre 中的所有内容放在一行中,如:

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

这不是我想要的。据我所知,我唯一的选择是在 Jade 中嵌入 HTML,如:

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

还有别的方法吗?

你想要转义HTML

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

或与#{}一起使用:

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