code - Including Angle Brackets In Pre Sections

admin2025-01-07  3

I am attempting to post some java code between pre tags but the angel brackets get removed. For example:

private HashMap<String, HashMap<String, Integer>> featureCounts;

becomes

private HashMap> featureCounts;

Is there a way I can render the actual code? Also I am not a php developer or a wordpress expert by any means, so modifying the underlying php would be less preferred as a solution. Is there a way I can do this just using the editor?

I am attempting to post some java code between pre tags but the angel brackets get removed. For example:

private HashMap<String, HashMap<String, Integer>> featureCounts;

becomes

private HashMap> featureCounts;

Is there a way I can render the actual code? Also I am not a php developer or a wordpress expert by any means, so modifying the underlying php would be less preferred as a solution. Is there a way I can do this just using the editor?

Share Improve this question asked Mar 27, 2013 at 15:57 David WilliamsDavid Williams 1391 bronze badge 1
  • If you don't mind a wiki-like syntax, you might give BlogText a try. I wrote this plugin (partially) to solve exactly your problem (as I'm a developer myself). – Sebastian Krysmanski Commented Mar 28, 2013 at 9:43
Add a comment  | 

2 Answers 2

Reset to default 1

If you're just trying to display them in a page or a post, you could try using their character entities. In the Text view in the editor, type &lt; instead of < and &gt; instead of >.

So, for instance, in your editor's Text view (not the Visual mode), you'd type:

<pre>
private HashMap&lt;String, HashMap&lt;String, Integer&gt;&gt; featureCounts;
</pre>

And that should do it.

you could try adding your code to a string, then using the php function htmlspecialchars()

$thecode = "private HashMap<String, HashMap<String, Integer>> featureCounts;\n";
$thecode.= "2nd line of code\n";
$thecode.= "3rd line of code\n";
$thecode.= "4th line of code\n";

the trim() function will remove any whitespace at the start & end of the string.

<pre><?php echo trim(htmlspecialchars($thecode));?></pre>

hope that helps.

转载请注明原文地址:http://conceptsofalgorithm.com/Algorithm/1736261222a724.html

最新回复(0)