CodeMirror HTML mode not working

前端 未结 2 1506
闹比i
闹比i 2020-12-30 20:44

I\'m trying to style code samples with CodeMirror, but it works partially - it applies the selected theme to the textarea but the syntax is not highlighted.

2条回答
  •  执念已碎
    2020-12-30 21:28

    CodeMirror parses HTML using the XML mode. To use it, the appropriate script must be included, same as with any other mode.

    Add its dependency in your markup:

    
    

    and set the mode to xml:

    config = {
        mode : "xml",
        // ...
    };
    

    In addition, you may want to configure the parser to allow for non well-formed XML. You can do so by switching the htmlMode flag on:

    config = {
        mode : "xml",
        htmlMode: true,
        // ...
    };
    

    See the XML/HTML mode demo for a live example.

提交回复
热议问题