Google Code Prettify在点击

时间:2017-07-12 06:13:12

标签: javascript jquery html google-code-prettify

我使用Google Code Prettify语法突出显示我的代码。这是我的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>

直接在HTML中将代码添加到xmlTextArea并替换所有&lt;和&gt;用&gt;和&lt;它确实有它的工作,但是当用这样的jquery设置代码时却没有:

$('#xmlTextArea').text(code)

我之后也尝试过调用PR.prettyPrint()

1 个答案:

答案 0 :(得分:0)

这是漂亮的代码。您可以参考code-prettify了解更多示例:

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>