文档类型(Doctype)

¥Doctype

文档类型快捷方式(Doctype Shortcuts)

¥Doctype Shortcuts

常用文档类型有快捷方式:

¥There are shortcuts for commonly used doctypes:

doctype html
<!DOCTYPE html>
doctype xml
<?xml version="1.0" encoding="utf-8" ?>
doctype transitional
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
doctype strict
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
doctype frameset
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Frameset//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-frameset.dtd">
doctype 1.1
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
doctype basic
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML Basic 1.1//EN" "http://www.w3.org/TR/xhtml-basic/xhtml-basic11.dtd">
doctype mobile
<!DOCTYPE html PUBLIC "-//WAPFORUM//DTD XHTML Mobile 1.2//EN" "http://www.openmobilealliance.org/tech/DTD/xhtml-mobile12.dtd">
doctype plist
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">

自定义文档类型(Custom Doctypes)

¥Custom Doctypes

你还可以使用自己的字面量自定义文档类型:

¥You can also use your own literal custom doctype:

文档类型选项(Doctype Option)

¥Doctype Option

除了在输出中缓冲之外,Pug 中的文档类型还可以通过其他方式影响编译。例如,自闭合标签是否以 />> 结尾取决于指定的是 HTML 还是 XML。布尔属性 的输出也可能受到影响。

¥In addition to being buffered in the output, a doctype in Pug can affect compilation in other ways. For example, whether self-closing tags end with /> or > depends on whether HTML or XML is specified. The output of boolean attributes may be affected as well.

如果出于某种原因无法使用 doctype 关键字(例如,仅渲染 HTML 片段),但你仍想指定模板的文档类型,则可以通过 doctype 选项 来执行此操作。

¥If, for whatever reason, it is not possible to use the doctype keyword (e.g., just rendering HTML fragments), but you would still like to specify the doctype of the template, you can do so via the doctype option.

var pug = require('pug');

var source = 'img(src="foo.png")';

pug.render(source);
// => '<img src="foo.png"/>'

pug.render(source, {doctype: 'xml'});
// => '<img src="foo.png"></img>'

pug.render(source, {doctype: 'html'});
// => '<img src="foo.png">'
Pug 中文网 - 粤ICP备13048890号