2017-05-24 56 views
1

我有一個混合需要titlecontentPug mixin - 在一個字符串中格式化html標記

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

當我使用的mixin只有文字它工作正常,但是當我添加的行內元素的字符串,如codebem,等它不創建它只是顯示哈巴狗標籤句法。

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

有了,我想的輸出是I have <b>bold</b> text
相反,它是創造I have #[b bold] text

有什麼事,以獲得期望的結果?

回答

0

這實際上是因爲默認情況下特殊字符獲得轉義序列替換。既然你不想要,只需用p!= content代替p = content即可。

所以,讓你的哈巴狗的代碼看起來像:

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') 
+0

那仍然以同樣的方式格式化它... –

+0

另外,您將html傳遞給mixin,它應該是pug語法 –

0

哈巴狗不會呈現文本的兩倍,但你可以把塊在你的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