Jade(Pug) Html 渲染输出
Jade(Pug) Html render output
我最近在Mac OS X Yosemite上安装了Jade(Pug)。
我安装了节点.js最新版本,然后使用终端命令:$ sudo npm install pug-cli -g
一切都很好,直到我不得不渲染文件。我用默认的哈巴狗代码创建了一个test.pug文件:
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
并渲染到测试中.html输出如下所示:
<!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
它输出如下:
<!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 中的正确输出自动呈现它?
您在
第一个变体 ( -P
) 中设置的选项启用输出美化。如果你想在第二个变体上使用它,只需添加标志:pug -P -w test.pug
从文档中:
-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)
检查 http://jade-lang.com/api/。
每个 API 方法(--pretty
CLI 中)都有一个 pretty
参数,如果启用该参数,可以使 Jade 输出可读(漂亮)HTML。
相关文章:
- 使用Jade输出HTML(在ng个重复内)
- 输出 html 表单数据
- 如何通过 AngularJS 模板输出 html
- Ajax 输出 html 注释
- 显示查询输出 HTML 中的图像
- HTML 代码不适用于 jquery 调用,而是输出 HTML 代码
- Html.ActionLink onclick JavaScript 函数未被调用,并且函数名称在输出 HTML 中已损
- Javascript -使用字符串输出HTML
- 如何正确使用jQuery从php输出html字符串
- 为什么.html()不输出html标签
- 如何获得一个变量's输出html值
- Twitter-text.js输出html作为纯文本
- 多行文本文件输出html
- 如何使用XSLT匹配元素和输出HTML
- 输出HTML代码
- 输出HTML时出现意外的令牌错误
- 用JavaScript输出HTML实体
- 在rjerb模板中输出HTML
- 从angularjs过滤器输出HTML,无需ng绑定HTML
- 获取实际输出HTML的函数