Ale*_*lex 54 javascript syntax-highlighting codemirror
可以CodeMirror 2被用来强调从代码DIV或PRE标签(无编辑)?
像CodeMirror 1曾经能够使用hightlightText()函数吗?例如:http://codemirror.net/1/highlight.html,按下运行高亮显示(下面突出显示的文本)
它也可以突出显示内联元素的代码<code>,并保持结果内联,就像谷歌的Prettify一样吗?
Sin*_*hus 53
一个更好,更简单的解决方案是将CodeMirror实例的readOnly属性设置为true,如下所示:
$('.code').each(function() {
var $this = $(this),
$code = $this.html();
$this.empty();
var myCodeMirror = CodeMirror(this, {
value: $code,
mode: 'javascript',
lineNumbers: !$this.is('.inline'),
readOnly: true
});
});
Run Code Online (Sandbox Code Playgroud)
只需将类添加.code到包含代码的标记中,它将突出显示语法.我还通过使用该类添加了对内联代码的支持.inline.