Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Jade: element attributes without value

Tags:

attributes

pug

I am new to using Jade -- and it's awesome so far.

But one thing that I need to happen is an element with 'itemscope' property:

<header itemscope itemtype="http://schema.org/WPHeader">

My Jade notation is:

header(itemscope, itemtype='http://schema.org/WPHeader')

But result is:

<header itemscope="itemscope" itemtype="http://schema.org/WPHeader">

How can I make sure that I get the right result -- itemscope instead of itemscope="itemscope"?

like image 369
mvbl fst Avatar asked Jun 13 '12 17:06

mvbl fst


5 Answers

Sometimes it doesn't work quite right -- like with contentEditable Jade tries to detect html5 doctypes and then does <header itemscope itemtype="http://schema.org/WPHeader"></header> if it finds it. The problem is that if you have templates that you are inserting in the page, it can't tell that it's html5.

What you can do is force html5 compilation by passing in {doctype: '5'} to the options -- did this for require-jade: https://github.com/ibash/require-jade/commit/754cba2dce7574b400f75a05172ec97465a8a5eb

like image 92
ibash Avatar answered Oct 18 '22 04:10

ibash


I had the same problem using angular ng-include directive. It gets ng-include="ng-include" and then the include doesn'nt work.

What it works for me is to use an empty string as a value, i.e. ng-include="".

like image 34
flacoloco Avatar answered Oct 18 '22 05:10

flacoloco


Here is answer from jade developers: you should use

  doctype html

in the template.

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

like image 41
alehro Avatar answered Oct 18 '22 04:10

alehro


I just tried it in a Express.js/Jade project and the result i get is:

<header itemscope itemtype="http://schema.org/WPHeader"></header>

I also tried it in bash and then I get the same result as you.

I'd go with the following suggestion or create an issue on Github.

itemscope="itemscope" will work just as well as just itemscope. It looks like that's the default behavior of Jade. I'd just go with it.

like image 23
Pickels Avatar answered Oct 18 '22 04:10

Pickels


I had the same problem, and the easiest solution in my case was adding doctype 5 at the top of my jade document. That apparently allows Jade to use attributes without a value. ibash put me on the right track with his answer, so thanks for that

like image 1
Bob Vork Avatar answered Oct 18 '22 04:10

Bob Vork