Jade:没有值的元素属性

mvb*_*fst 12 attributes pug

我是新手使用Jade - 到目前为止它真棒.

但我需要做的一件事是带有'itemscope'属性的元素:

<header itemscope itemtype="http://schema.org/WPHeader">
Run Code Online (Sandbox Code Playgroud)

我的玉符号是:

header(itemscope, itemtype='http://schema.org/WPHeader')
Run Code Online (Sandbox Code Playgroud)

但结果是:

<header itemscope="itemscope" itemtype="http://schema.org/WPHeader">
Run Code Online (Sandbox Code Playgroud)

我怎样才能确保得到正确的结果 - itemscope而不是itemscope="itemscope"

iba*_*ash 12

有时它不能正常工作 - 就像contentEditableJade尝试检测html5文档类型一样,<header itemscope itemtype="http://schema.org/WPHeader"></header>如果找到它就会发生.问题是,如果你有插入页面的模板,它不能告诉它是html5.

你可以做的是通过传入{doctype: '5'}选项强制html5编译- 为require-jade做这个:https://github.com/ibash/require-jade/commit/754cba2dce7574b400f75a05172ec97465a8a5eb

  • 我相信语法现在是`{doctype:'html'}` (5认同)

小智 10

我使用angular ng-include指令遇到了同样的问题.它获得ng-include ="ng-include",然后包含不起作用.

它对我有用的是使用空字符串作为值,即ng-include ="".


ale*_*hro 7

以下是玉石开发商的回答:你应该使用

  doctype html
Run Code Online (Sandbox Code Playgroud)

在模板中.

https://github.com/pugjs/jade/issues/370


Pic*_*els 6

我刚刚在Express.js/Jade项目中尝试过它,我得到的结果是:

<header itemscope itemtype="http://schema.org/WPHeader"></header>
Run Code Online (Sandbox Code Playgroud)

我也在bash中尝试过,然后我得到与你相同的结果.

我会提出以下建议或在Github上创建一个问题.

itemscope ="itemscope"将与itemscope一样有效.看起来这是Jade的默认行为.我跟它一起去.