0

代码镜像问题

$('.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
});

});

我正在使用 codemirror 创建代码片段。我有两个问题。首先是javascript没有正确着色。我已经包含了所有依赖项(xml、css 和 js)。第二个是当我将鼠标悬停在 上时,滚动会导致片段略微向上或向下移动。它不是完全滚动,只是摆动。有关更多详细信息,请参见图像。

所有帮助将不胜感激。

4

1 回答 1

0
$('.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"
    });
   });

这对我来说很好用

于 2017-05-11T13:08:26.663 回答