简体   繁体   English

codemirror html混合模式未应用于JavaScript

[英]codemirror html mixed mode not being applied to JavaScript

代码镜像问题

$('.code').each(function() {
var $this = $(this),
$code = $this.html();

$this.empty();

var myCodeMirror = CodeMirror(this, {
    value: $code,
    mode: 'htmlmixed',
    lineNumbers: false,
    readOnly: true,
    lineWrapping: true
});

}); });

I'm using codemirror to create code snippets. 我正在使用Codemirror创建代码片段。 I'm having two issues. 我有两个问题。 The first is that javascript isn't being colored properly. 首先是javascript的颜色不正确。 I've included all the dependencies (xml, css and js). 我已经包含了所有依赖项(xml,css和js)。 The second is that when I hover over the , scrolling causes the snippet to move slightly up or down. 第二个是,当我将鼠标悬停在上时,滚动会导致代码段稍微向上或向下移动。 It isn't quite scrolling, just wiggling. 它不是很滚动,只是摇摆不定。 See image for more details. 请参阅图像以获取更多详细信息。

All help would be greatly appreciated. 所有帮助将不胜感激。

$('.code).each(function() {
     var $this = $(this),
     $code = $this.html(),
     $unescaped = $('<div/>').html($code).text();
     $this.empty();
     CodeMirror(this, {
      value: $unescaped,
      lineNumbers: true,
      theme: "neo",
      readOnly: "nocursor"
    });
   });

This was working fine for me 这对我来说很好

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM