我有一个HTML页面,需要显示一些日志信息。我将它们包裹在
这是我的HTML页面:
<pre></pre>
中,但它似乎将日志消息解释为HTML,我希望它以原始方式打印出来。我尝试了"在HTML中显示纯文本,就像文本编辑器一样"或"防止<code>标签中的自动换行"或"如何使用CSS保留HTML中<code>块中的换行符?"等建议,但都不起作用(它们给出与我的原始HTML相同的结果)。这是我的HTML页面:
code {
font-size: 14px;
display: block;
font-family: monospace;
white-space: pre;
margin: 1em 0;
}
body {
font-family: Arial;
}
<div>
<h3>pre and code:</h3>
<pre>
<code>
[2016-06-24 16:06:00]|DEBUG|...., details='#<hashie::mash worker_address="http://xxx.amazonaws.com:8081" worker_id="0000000008" worker_task_id="776f31e01c530134025722000b27033c:gather_source_file_info_task_1466784360">'
</code>
</pre>
</div>
<div>
<h3>only code:</h3>
<code>
[2016-06-24 16:06:00]|DEBUG|...., details='#<hashie::mash worker_address="http://xxx.amazonaws.com:8081" worker_id="0000000008" worker_task_id="776f31e01c530134025722000b27033c:gather_source_file_info_task_1466784360">'
</code>
</div>
<div>
<h3>only pre:</h3>
<pre>
[2016-06-24 16:06:00]|DEBUG|...., details='#<hashie::mash worker_address="http://xxx.amazonaws.com:8081" worker_id="0000000008" worker_task_id="776f31e01c530134025722000b27033c:gather_source_file_info_task_1466784360">'
</pre>
</div>
以下是在浏览器上的渲染效果(使用的是最新版的Mac Chrome):
pre and code:
[2016-06-24 16:06:00]|DEBUG|...., details='#'
only code:
[2016-06-24 16:06:00]|DEBUG|...., details='#'
only pre:
[2016-06-24 16:06:00]|DEBUG|...., details='#'
注意缺少的hashie::mash
我希望它打印出来的是:
[2016-06-24 16:06:00]|DEBUG|...., details='#<hashie::mash worker_address="http://xxx.amazonaws.com:8081" worker_id="0000000008" worker_task_id="776f31e01c530134025722000b27033c:gather_source_file_info_task_1466784360">'
当日志包含一些XML时,我遇到类似的问题。