翡翠中的doctype声明

时间:2016-02-11 12:18:06

标签: node.js pug template-engine

我试图在输出代码(包括回车)之后在Jade中重新生成但没有成功:

尝试输出以下内容:

<?xml version="1.0"?>
<!DOCTYPE j:jelly 
[
  <!ENTITY aacute "&#x000E1;">
  <!ENTITY Aacute "&#x000C1;">
  <!ENTITY ordm "&#x000BA;">
  <!ENTITY euro "&#x020AC;">
  <!ENTITY amp  "&#x00026;">
  <!ENTITY iquest  "&#x000BF;">
  <!ENTITY iexcl  "&#x000A1;">
  <!ENTITY copy  "&#x000A9;">
]>

Jade代码中我有:

<?xml version="1.0"?>
doctype j:jelly[<!ENTITY aacute "&#x000E1;"><!ENTITY Aacute "&#x000C1;"><!ENTITY eacute "&#x000E9;"><!ENTITY ordm "&#x000BA;"><!ENTITY euro "&#x020AC;"><!ENTITY amp  "&#x00026;"><!ENTITY iquest  "&#x000BF;"><!ENTITY iexcl  "&#x000A1;"><!ENTITY copy  "&#x000A9;"> ]

输出一行(工作但很乱,没有回车):

<?xml version="1.0"?>
<!DOCTYPE j:jelly [<!ENTITY aacute "&#x000E1;"><!ENTITY Aacute "&#x000C1;"><!ENTITY ordm "&#x000BA;"><!ENTITY euro "&#x020AC;"><!ENTITY amp  "&#x00026;"><!ENTITY iquest  "&#x000BF;"><!ENTITY iexcl  "&#x000A1;"><!ENTITY copy  "&#x000A9;">]>

1 个答案:

答案 0 :(得分:0)

所以只需在原始文本中添加换行符:

<?xml version="1.0"?> 
| < doctype j:jelly
| [
|  <!ENTITY aacute "&#x000E1;">
|  <!ENTITY Aacute "&#x000C1;">
|  <!ENTITY eacute "&#x000E9;">
|  <!ENTITY ordm "&#x000BA;">
|  <!ENTITY euro "&#x020AC;">
|  <!ENTITY amp  "&#x00026;">
|  <!ENTITY iquest  "&#x000BF;">
|  <!ENTITY iexcl  "&#x000A1;">
|  <!ENTITY copy  "&#x000A9;">
| ]>

获取

<?xml version="1.0"?> 
< doctype j:jelly
[
 <!ENTITY aacute "&#x000E1;">
 <!ENTITY Aacute "&#x000C1;">
 <!ENTITY eacute "&#x000E9;">
 <!ENTITY ordm "&#x000BA;">
 <!ENTITY euro "&#x020AC;">
 <!ENTITY amp  "&#x00026;">
 <!ENTITY iquest  "&#x000BF;">
 <!ENTITY iexcl  "&#x000A1;">
 <!ENTITY copy  "&#x000A9;">
]>

因为这只使用原始文本,所以您可以考虑使用include语句。

<强> start.jade

include ./other.jade

<强> other.jade

<?xml version="1.0"?> 
< doctype j:jelly
[
 <!ENTITY aacute "&#x000E1;">
 <!ENTITY Aacute "&#x000C1;">
 <!ENTITY eacute "&#x000E9;">
 <!ENTITY ordm "&#x000BA;">
 <!ENTITY euro "&#x020AC;">
 <!ENTITY amp  "&#x00026;">
 <!ENTITY iquest  "&#x000BF;">
 <!ENTITY iexcl  "&#x000A1;">
 <!ENTITY copy  "&#x000A9;">
]>

你会得到

/usr/lib/node_modules/jade/lib/runtime.js:240
  throw err;
        ^
Error: other.jade:3
    1| <?xml version="1.0"?> 
    2| < doctype j:jelly
  > 3| [
    4|  <!ENTITY aacute "&#x000E1;">
    5|  <!ENTITY Aacute "&#x000C1;">
    6|  <!ENTITY eacute "&#x000E9;">

unexpected text [
 <!
    at Object.Lexer.fail (/usr/lib/node_modules/jade/lib/lexer.js:887:11)
    at Object.Lexer.next (/usr/lib/node_modules/jade/lib/lexer.js:947:15)
    at Object.Lexer.lookahead (/usr/lib/node_modules/jade/lib/lexer.js:113:46)
    at Parser.lookahead (/usr/lib/node_modules/jade/lib/parser.js:102:23)
    at Parser.peek (/usr/lib/node_modules/jade/lib/parser.js:79:17)
    at Parser.parse (/usr/lib/node_modules/jade/lib/parser.js:117:26)
    at Parser.parseInclude (/usr/lib/node_modules/jade/lib/parser.js:616:22)
    at Parser.parseExpr (/usr/lib/node_modules/jade/lib/parser.js:223:21)
    at Parser.parse (/usr/lib/node_modules/jade/lib/parser.js:122:25)
    at parse (/usr/lib/node_modules/jade/lib/index.js:104:21)

因为要包含的文件被解释为jade模板。只需重命名即可。

<强> start.jade

include ./other.inc

<强> other.inc

<?xml version="1.0"?> 
< doctype j:jelly
[
 <!ENTITY aacute "&#x000E1;">
 <!ENTITY Aacute "&#x000C1;">
 <!ENTITY eacute "&#x000E9;">
 <!ENTITY ordm "&#x000BA;">
 <!ENTITY euro "&#x020AC;">
 <!ENTITY amp  "&#x00026;">
 <!ENTITY iquest  "&#x000BF;">
 <!ENTITY iexcl  "&#x000A1;">
 <!ENTITY copy  "&#x000A9;">
]>

您将获得预期的

<?xml version="1.0"?> 
< doctype j:jelly
[
 <!ENTITY aacute "&#x000E1;">
 <!ENTITY Aacute "&#x000C1;">
 <!ENTITY eacute "&#x000E9;">
 <!ENTITY ordm "&#x000BA;">
 <!ENTITY euro "&#x020AC;">
 <!ENTITY amp  "&#x00026;">
 <!ENTITY iquest  "&#x000BF;">
 <!ENTITY iexcl  "&#x000A1;">
 <!ENTITY copy  "&#x000A9;">
]>