【问题标题】:Prettyprint xml not highlightingPrettyprint xml没有突出显示
【发布时间】:2016-04-22 17:38:40
【问题描述】:

我正在尝试漂亮打印一些由自定义安装的 blockly 生成的代码。生成的代码将是 xml,但问题是,一旦我尝试使用 google prettify 突出显示代码(而不是唯一一个,与 higlight.js 相同的问题),代码没有突出显示,我尝试 google 但所有解决方案都没有似乎不适用于我的问题。

这就是我导入美化库的方式:

这是代码:

<script language="javascript">
    function showCode() {
        var code = Blockly.JavaScript.workspaceToCode(workspace);
        var element = document.getElementById("codeview");
        var pre_element = document.createElement("pre");
        pre_element.setAttribute("class", "prettyprint");
        pre_element.setAttribute("id", "code_container");
        pre_element.textContent = Blockly.JavaScript.workspaceToCode(workspace);
        //pre_element.appendChild(code_element);
        element.appendChild(pre_element);
        //alert(code);
      }
</script>

生成代码的示例之一是:

<property name='default' />
<property name='default' />
<property name='default' />

现在我不知道问题是我需要在我美化的代码中指定文档类型,还是只是别的东西,例如我需要转义它?两个都?

应用程序托管在 Spring Boot 应用程序上。 Blockly 工作正常,但问题似乎只出在语法荧光笔上。

【问题讨论】:

    标签: javascript xml google-code-prettify


    【解决方案1】:

    我想你不会在 HTML 的 &lt;body&gt; 中调用 prettyprint() 函数。

    在添加pre_element 后调用prettyprint()

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-10-15
      • 2012-02-10
      • 1970-01-01
      • 1970-01-01
      • 2015-07-21
      • 1970-01-01
      • 2017-01-19
      相关资源
      最近更新 更多