Вопрос

If I try the following test case with prettify, if doesn't work correctly.

<!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>

The output reads "for(int i = 0; i " which suggests it failed to handle the less-than correctly.

I have submitted a bug to the project, but I wonder if there is a workaround I can use in the meantime?

It's possible to workaround this by tweaking the input source code, e.g. changing it to "for(int i =0; i < things.length; i++)" (adding a space after the less-than). However, I can't rely on doing this, as my tool runs unattended on client sites. However, I'd be happy to hack at Prettify, or run the source code through some kind of pre-filter.

Recommendations on alternatives to prettify are welcome.

Это было полезно?

Решение

Literal < and > characters in HTML documents should be encoded as entities, so it should be:

<pre class="prettyprint lang-java">
for(int i = 0; i &lt; things.length; i++)
</pre>
Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top