首页 > 解决方案 > 如何确定 Pugjs (jade) 上的块注释结束?

问题描述

如何在子元素之前使用块注释将元素添加到父元素?我试图这样做,但它给了我两个选择:

1-使子元素成为兄弟元素!我不想

body
    main
        .main-container#main
             // this is a comment will apper on html file
             //- this is a comment will not apper on html file 
        p hello

2-如果我给它2个缩进,子元素将成为块注释的一部分,如果我给它一个缩进它会引发错误!

body
    main
        .main-container#main
             // this is a comment will apper on html file
             //- this is a comment will not apper on html file 
            p hello

标签: pug

解决方案


注释和段落元素都应该与其父元素的子元素处于相同的缩进级别:

body
  main#main
    .main-container
      // this comment will appear in compiled HTML
      //- this comment won't appear in compiled HTML
      p hello
    

请注意,注释语法的第一个正斜杠与p.


推荐阅读