How can I add a style tag in the header with jade/pug?

pug
grahamrhay picture grahamrhay · Jul 7, 2016 · Viewed 16.8k times · Source

I want something like this:

html
  head
    style(type="text/css")
      table {
        width: 100%
      }
  body
    table

But can't find the right incantation. This results in an "unexpected text" error. I tried escaping the css with a |, to no avail; and the best I've achieved so far is getting a table tag rendered in the header :(

Is it possible to do this with jade/pug?

Answer

Iso picture Iso · Jul 9, 2016

Yes, you can add arbitrary text to any tag by suffixing it with a dot:

style(type="text/css").
  table {
    width: 100%
  }

In the documentation: https://pugjs.org/language/plain-text.html#recommended-solutions