官网是这样介绍的:
Here's a simple example of using RequireJS to load CodeMirror:
require([
"cm/lib/codemirror", "cm/mode/htmlmixed/htmlmixed"
], function(CodeMirror) {
CodeMirror.fromTextArea(document.getElementById("code"), {
lineNumbers: true,
mode: "htmlmixed"
});
});
It will automatically load the modes that the mixed HTML mode depends on (XML, JavaScript, and CSS). Do not use RequireJS' paths option to configure the path to CodeMirror, since it will break loading submodules through relative paths. Use the packages configuration option instead, as in:
require.config({
packages: [{
name: "codemirror",
location: "../path/to/codemirror",
main: "lib/codemirror"
}]
});
我是从http://codemirror.net/codemir...下载的。
我的HTML是
测试加载 CodeMirror DEMO
然后requirejsdemo.js的内容是:
require.config({
packages: [{
name: "codemirror",
location: "/public/static/libs/codemirror/lib",
main: 'codemirror'
},{
name: "mode_javascript",
location: "/public/static/libs/codemirror/mode/javascript",
main: 'javascript'
}]
});
require(["codemirror", "mode_javascript"], function(CodeMirror) {
CodeMirror.fromTextArea(document.getElementById("textarea"), {
lineNumbers: true,
mode: "javascript"
});
});
结果,lineNumbers是生效了,真的出现了行号。然而着色却根本没有。
我似乎是姿势不对,求正确姿势!谢谢!
Copyright 2014-2026 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号
认证高级PHP讲师