【问题标题】:Google Code Prettify doesnt syntax highlight on clickGoogle Code Prettify 在点击时不会突出显示语法
【发布时间】:2017-07-12 06:13:11
【问题描述】:

我使用 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 并将所有 替换为 > 和

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

之后我也尝试拨打PR.prettyPrint()

【问题讨论】:

    标签: javascript jquery html google-code-prettify


    【解决方案1】:

    这是漂亮的代码。更多示例可以参考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>

    【讨论】:

    • 正如我所说,这样做是可行的,但在通过 jquery 添加代码时却不行
    • 通过JQuery添加了相同的,除了可以注意的格式之外,它可以工作。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-03-10
    • 2017-07-06
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多