0

我使用 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 并将所有 < 和 > 替换为 > 和 < 时,它就可以了,但在使用 jquery 设置代码时却不是这样:

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

PR.prettyPrint()之后我也试着打电话

4

1 回答 1

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>

于 2017-07-12T07:53:14.077 回答