0

I'm trying to prettyprint some code generated by a custom installation of blockly. The code generated will be xml, but the problem is that once I try to highlight the code using google prettify (and not the only one, same problem with higlight.js) the code is not highlighted, I tried to google but all solution doesn't appear to apply to my problem.

This is how I imported the prettify library:

This is the code:

<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>

one of the example of generated code is:

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

Now I don't know if the problem is that I need to specify the doctype in the piece of code I'm prettifying, or it's just something else, maybe for example I need to escape it? Both?

The application is hosted on a Spring Boot App. Blockly works fine, but the problem appear to be only with the syntax highlighter.

4

1 に答える 1