怎么样才能将HTML格式化输出

html-css013

怎么样才能将HTML格式化输出,第1张

使用的是expressjs中hbs(HandlerBars)的模板引擎,输出的HTML格式非常乱,用过第三方插件html中的prettyPrint 可以将html格式化输出。

我现在想问的是express用没有设置让res.render的html自动格式化,不需要第三方插件支持。

html格式化标签有这么多,整理了一下,如下:

<b> 定义粗体文本。

<big> 定义大号字。

<em> 定义着重文字。

<i> 定义斜体字。

<small> 定义小号字。

<strong> 定义加重语气。

<sub> 定义下标字。

<sup> 定义上标字。

<ins> 定义插入字。

<del> 定义删除字。

<code> 定义计算机代码。

<kbd> 定义键盘码。

<samp> 定义计算机代码样本。

<tt> 定义打字机代码。

<var> 定义变量。

<pre> 定义预格式文本。

<abbr> 定义缩写。

<acronym> 定义首字母缩写。

<address> 定义地址。

<bdo> 定义文字方向。

<blockquote> 定义长的引用。

<q> 定义短的引用语。

<cite> 定义引用、引证。

<dfn> 定义一个定义项目。

<html>

<head>

<meta http-equiv=content-type content="text/htmlcharset=GBK">

</head>

<body>

<table border=0 cellspacing=0 cellpadding=0>

<tr>

<td id="a">sdfsd</td>

</tr>

<tr>

<td id="b">sdfsdf</td>

</tr>

<tr>

<td id="c">sdfsd</td>

</tr>

<tr>

<td id="d">sdfsdf</td>

</tr>

</table>

</body>

<script>

var jsonStr = "{\"a\":\"内容1\", \"b\":\"内容2\",\"c\":\"内容3\",\"d\":\"内容4\"}"

var jsonObj = eval("(" + jsonStr + ")")

for(var property in jsonObj){

var nodeObj = document.getElementById(property)

if(nodeObj)

nodeObj.childNodes[0].nodeValue = jsonObj[property]

}

</script>

</html>