0

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

Flo
  • 2,699
  • 4
  • 24
  • 46

1 Answers1

0

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>
Milan Chheda
  • 8,159
  • 3
  • 20
  • 35