I want to display Java source code in an html site.
When I escape all > and < before pasting the code into the html, it obviously works, everything is displayed correctly.
When I don't, a HashMap is displayed like this:
HashMapclass="string">"">> map = new HashMap<>();
which should be
HashMap<String, ArrayList<String>> map = new HashMap<>();
When I use JQuery's text() method and print the result to the console, I get this:
HashMap> map = new HashMap<>();
And when I use the html() method, I get this:
HashMap<string, arraylist<string="">> map = new HashMap<>();
How should I retrieve the text from the code-Element so that I can correctly escape > and
Doing the same thing with XML source code works. I use
$(this).html()
to get the text in the code-Element and then escape the characters. The XML is then displayed with tags instead of just text.