首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Jade(Pug) Html呈现输出

Jade(Pug) Html呈现输出
EN

Stack Overflow用户
提问于 2016-07-11 09:38:02
回答 2查看 7.8K关注 0票数 2

我最近在上安装了Jade(Pug)。

我安装了最后一个版本的node.js,然后使用了终端命令:$ sudo npm install pug-cli -g

一切都很好,直到我把文件呈现出来。我使用默认的pug代码创建了一个test.pug文件:

代码语言:javascript
复制
doctype html
html(lang="en")
  head
    title= pageTitle
    script(type='text/javascript').
      if (foo) bar(1 + 5)
  body
    h1 Pug - node template engine
    #container.col
      if youAreUsingPug
        p You are amazing
      else
        p Get on it!
      p.
        Pug is a terse and simple templating language with a
        strong focus on performance and powerful features.

然后用终端来渲染它来测试它。我使用了:$ pug -P test.pug并将其呈现给test.html,输出如下所示:

代码语言:javascript
复制
<!DOCTYPE html>
<html lang="en">
  <head>
    <title></title>
    <script type="text/javascript">if (foo) bar(1 + 5)</script>
  </head>
  <body>
    <h1>Pug - node template engine</h1>
    <div class="col" id="container">
      <p>Get on it!</p>
      <p>
        Pug is a terse and simple templating language with a
        strong focus on performance and powerful features.
      </p>
    </div>
  </body>
</html>

现在,当我想自动呈现它并使用-watch特性:$ pug -w test.pug时,它的输出如下:

代码语言:javascript
复制
<!DOCTYPE html><html lang="en"><head><title></title><script type="text/javascript">if (foo) bar(1 + 5)</script></head><body><h1>Pug - node template engine</h1><div class="col" id="container"><p>Get on it!</p><p>Pug is a terse and simple templating language with a
strong focus on performance and powerful features.</p></div></body></html>

我找不到解决办法。对于我在youtube或其他教程上看到的其他人来说,输出看起来具有正确的HTML结构,但我的输出呈现成一个缩小的版本。

我能做些什么来修复这个问题,并让它用HTML的正确输出自动呈现呢?

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2016-07-11 23:18:47

在第一个变体(-P)中设置的选项启用输出美化。如果您想在第二个变体上使用它,只需添加标志:pug -P -w test.pug

从医生那里:

代码语言:javascript
复制
-h, --help             output usage information
-V, --version          output the version number
-O, --obj <path|str>   JavaScript options object or JSON file containing it
-o, --out <dir>        output the compiled html to <dir>
-p, --path <path>      filename used to resolve includes
-P, --pretty           compile pretty html output
-c, --client           compile function for client-side runtime.js
-n, --name <str>       the name of the compiled template (requires --client)
-D, --no-debug         compile without debugging (smaller functions)
-w, --watch            watch files for changes and automatically re-render
-E, --extension <ext>  specify the output file extension
--name-after-file      name the template after the last section of the file path
                       (requires --client and overriden by --name)
--doctype <str>        specify the doctype on the command line (useful if it
                       is not specified by the template)
票数 6
EN

Stack Overflow用户

发布于 2016-07-11 12:10:55

检查http://jade-lang.com/api/

在每个API方法(CLI中的pretty )中都有一个--pretty参数,如果启用,Jade输出就可以读取(漂亮)--pretty

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/38303672

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档