如何将 CodeMirror 合并到我的项目中?
How to incorporate CodeMirror into my project?
我和我的朋友正在一起开发一个项目,这个项目将包括一个浏览器 html、javascript 和 css 编辑器。我意识到在浏览器编辑器中编写代码的功能会很困难——这就是我决定为这个项目使用 CodeMirror 功能的原因。但是,我在将 CodeMirror 整合到这个项目中时遇到了一些麻烦。我已经下载了 CodeMirror,现在卡住了!请问有人能帮忙吗?
如有任何帮助,我们将不胜感激。
将以下内容保存到例如path/to/codemirror/test.html
(在 codemirrors index.html 和 lib,mode 文件夹旁边),在任何合适的浏览器中打开它,并为您的冒险尝试找到一个起点:
<html>
<script src="lib/codemirror.js"></script>
<link rel="stylesheet" href="lib/codemirror.css">
<script src="mode/javascript/javascript.js"></script>
<script src="mode/htmlmixed/htmlmixed.js"></script>
<script src="mode/xml/xml.js"><!-- needed for htmlmixed --></script>
<script src="mode/css/css.js"></script>
<form>
<fieldset>
<legend>HTML</legend>
<textarea id="htmlCode"><html><h1>E<span style="color:red">x</span>ample</h1></html></textarea>
</fieldset>
<fieldset>
<legend>CSS</legend>
<textarea id="cssCode">.foo { font-weight: bold; }</textarea>
</fieldset>
<fieldset>
<legend>JS</legend>
<textarea id="jsCode">function myScript(){return 100;}</textarea>
</fieldset>
</form>
<script>
window.onload = function () {
CodeMirror.fromTextArea(document.getElementById('htmlCode'), {mode: 'htmlmixed'})
CodeMirror.fromTextArea(document.getElementById('cssCode'), {mode: 'css'})
CodeMirror.fromTextArea(document.getElementById('jsCode'), {mode: 'javascript', lineNumbers:true})
};
</script>
</html>
我和我的朋友正在一起开发一个项目,这个项目将包括一个浏览器 html、javascript 和 css 编辑器。我意识到在浏览器编辑器中编写代码的功能会很困难——这就是我决定为这个项目使用 CodeMirror 功能的原因。但是,我在将 CodeMirror 整合到这个项目中时遇到了一些麻烦。我已经下载了 CodeMirror,现在卡住了!请问有人能帮忙吗?
如有任何帮助,我们将不胜感激。
将以下内容保存到例如path/to/codemirror/test.html
(在 codemirrors index.html 和 lib,mode 文件夹旁边),在任何合适的浏览器中打开它,并为您的冒险尝试找到一个起点:
<html>
<script src="lib/codemirror.js"></script>
<link rel="stylesheet" href="lib/codemirror.css">
<script src="mode/javascript/javascript.js"></script>
<script src="mode/htmlmixed/htmlmixed.js"></script>
<script src="mode/xml/xml.js"><!-- needed for htmlmixed --></script>
<script src="mode/css/css.js"></script>
<form>
<fieldset>
<legend>HTML</legend>
<textarea id="htmlCode"><html><h1>E<span style="color:red">x</span>ample</h1></html></textarea>
</fieldset>
<fieldset>
<legend>CSS</legend>
<textarea id="cssCode">.foo { font-weight: bold; }</textarea>
</fieldset>
<fieldset>
<legend>JS</legend>
<textarea id="jsCode">function myScript(){return 100;}</textarea>
</fieldset>
</form>
<script>
window.onload = function () {
CodeMirror.fromTextArea(document.getElementById('htmlCode'), {mode: 'htmlmixed'})
CodeMirror.fromTextArea(document.getElementById('cssCode'), {mode: 'css'})
CodeMirror.fromTextArea(document.getElementById('jsCode'), {mode: 'javascript', lineNumbers:true})
};
</script>
</html>