在某些情况下,美化不能处理得更少

Prettify fails to handle less-than in certain circumstances

本文关键字:处理 不能 情况下      更新时间:2023-09-26

如果我尝试使用下面的美化测试用例,它不能正确工作。

<!DOCTYPE html>
<head><script src="https://google-code-prettify.googlecode.com/svn/loader/run_prettify.js"></script></head>
<body>
<pre class="prettyprint lang-java">
for(int i = 0; i <things.length; i++)
</pre>
</body></html>

输出为"for(int i = 0;I ",这表明它未能正确处理小于。

我已经提交了一个错误的项目,但我想知道是否有一个变通方法,我可以在此期间使用?

可以通过调整输入源代码来解决这个问题,例如将其更改为"for(int i =0;我& lt;things.length;我+ +)"(在小于后面加一个空格)。但是,我不能依赖于这样做,因为我的工具在客户端站点上无人值守地运行。但是,我很乐意在Prettify上进行hack,或者通过某种预过滤器运行源代码。

文字<>字符在HTML文档中应该被编码为实体,所以它应该是:

<pre class="prettyprint lang-java">
for(int i = 0; i &lt; things.length; i++)
</pre>