简体   繁体   English

Pug mixin —在字符串中格式化html标记

[英]Pug mixin — Format html markup within a string

I have a mixin that takes a title and content . 我有一个带有titlecontent的mixin。

mixin card-header(title, content)
  .card.section
    .card-header.secondary-color.white-text
      h4.card-title= title
    .card-body
      p= content

When I use the mixin with just text It works fine, but when I add inline elements to the string such as code , b , em , etc. it doesn't create the tags it just displays the pug syntax. 当我仅使用文本使用mixin时,它可以很好地工作,但是当我向codebem等字符串中添加内联元素时,它不会创建标签,而只会显示pug语法。

+card-header('Page Header', 'I have #[b bold] text')

With that I would like the the output to be I have <b>bold</b> text 这样,我希望输出是I have <b>bold</b> text
Instead it is creating I have #[b bold] text 相反,它正在创建I have #[b bold] text

What can I do to get the desired result? 我该怎么做才能获得理想的结果?

This is actually happening because special characters are by default getting an escape sequence replacement. 这实际上是在发生,因为默认情况下特殊字符会得到转义序列替换。 Since you do not want that, simply replace p= content with p!= content. 由于不希望这样,只需将p = content替换为p!= content。

So, make your pug code look like that: 因此,使您的哈巴狗代码如下所示:

mixin card-header(title, content)
  .card.section
    .card-header.secondary-color.white-text
      h4.card-title= title
    .card-body
      p!= content

+card-header('Page Header', 'I have <b>bold</b> text')

The pug won't render the text twice, but you can put a block in your mixin like this: 哈巴狗不会两次渲染文本,但是您可以像这样在mixin中放置一个块:

mixin card-header(title, content)
    .card.section
        .card-header.secondary-color.white-text
            h4.card-title= title
        .card-body
            block

+card-header('Page Header')
    p I have #[b bold] text

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM