I use Google Code Prettify to syntax highlight my code. This is my HTML
<head>
<script src="https://cdn.rawgit.com/google/code-prettify/master/loader/run_prettify.js"></script>
</head>
<body>
<div id ="xmlView">
<pre class="prettyprint">
<code class="language-xml" id="xmlTextArea"></code>
</pre>
</div>
</body>
When adding Code directly in HTML to xmlTextArea and replacing all < and > with > and < it does it's job, but not when setting the code with jquery like this:
$('#xmlTextArea').text(code)
I also tried to call PR.prettyPrint()
afterwards
Here is the pretty code. You can refer to code-prettify for more examples:
var someCode = 'class Voila {public:static const string VOILA = "Voila";<a href="#voila2">tags</a>.}'; $('.prettyprint').html(someCode);
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <head> <script src="https://cdn.rawgit.com/google/code-prettify/master/loader/run_prettify.js"></script> </head> <body> <div id="xmlView"> <pre class="prettyprint"></pre> </div> </body>
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.