pug笔记

作者: TOPro | 来源:发表于2018-11-13 11:03 被阅读12次
  • html转义
    p  以下链接:<Internet Explorer>、<Google Chrome>、<Mozilla Firefox>、<Safari> 和 <Opera>。
    
    这段pug是无法编译的会提示标签没有结束, 解决办法1,是使用html转义字符代替<,>,下面是更优雅的解决方法
    p!= `以下链接:<Internet Explorer>、<Google Chrome>、<MozillaFirefox>、<Safari> 和 <Opera>`
    
    官网示例
    p
      = '这个代码被 <转义> 了!'
    //或者
    p= '这个代码被 <转义> 了!'
    //结果
    //<p>这个代码被 &lt;转义&gt; 了!</p>
    
    p
      != '这段文字 <strong>没有</strong> 被转义!'
    //或者
    p!= '这段文字' + ' <strong>没有</strong> 被转义!'
    //结果
    //<p>这段文字 <strong>没有</strong> 被转义!</p>
    
  • 块展开
    a: img
    //<a><img/></a>
    
  • 自闭和标签
    foo/
    //<foo/>
    foo(bar='baz')/
    //<foo bar="baz" />
    
  • 标签中的纯文本块
    script.
      if (usingPug)
        console.log('这是明智的选择。')
      else
        console.log('请用 Pug。')
    //script推荐用法
    div
      p This text belongs to the paragraph tag.
      br
      .
       This text belongs to the div tag.
    //<p>This text belongs to the paragraph tag.</p><br/>This
    //text belongs to the div tag.</div>
    

相关文章