我有一个标签:
<pre>
this is a
this is b
this is c
</pre>
浏览器解析后输出:
this is a
this is b
this is c
我想要的是:
this is a
this is b
this is c
有什么办法可以仅使用客户端方法去做这个?
Change <pre>
tag to <div>
?但它变成了单行,不是我想要的。
添加CSS?我没有找到一种风格来实现。
或者使用JavaScript?
PS: 中的内容<pre>
标签由液体模板生成{{ post.content}}
, 这是不可变的.
修剪并过滤掉空行。
// get the pre tag
var pre = document.querySelector('pre');
pre.innerHTML = pre.innerHTML
// split by new line
.split('\n')
// iterate and trim out
.map(function(v) {
return v.trim()
// filter out non-empty string
}).filter(function(v) {
return v != '';
// join using newline char
}).join('\n')
<pre>
this is a
this is b
this is c
</pre>
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)