gpt4 book ai didi

css - HTML 显示原始文本

转载 作者:太空宇宙 更新时间:2023-11-04 14:30:16 25 4
gpt4 key购买 nike

我有一个 HTML 页面,我需要在其中显示一些日志消息。我把它们包裹在 <pre></pre> 里了,但它似乎将日志消息解释为 HTML,我希望它以原始格式打印。我尝试了“Displaying raw text in HTML like a text editor”或“Prevent automatic line breaks in a <code> tag”或“How can I use CSS to preserve line breaks in an HTML <code> block?”中给出的建议,但都没有用(它们给出的结果与我原来的 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 时,我遇到了类似的问题。

最佳答案

我知道的最简单方法:使用 <textarea>

textarea { white-space: nowrap; }
<textarea rows="8" cols="50" >
[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">'
</textarea>

关于css - HTML 显示原始文本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38019809/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com