本篇内容介绍了“js代码在线运行的方法”的有关知识,在实际案例的操作过程中,不少人都会遇到这样的困境,接下来就让小编带领大家学习一下如何处理这些情况吧!希望大家仔细阅读,能够学有所成!
1.codemirror概念
codemirror 基于Javascript,短小精悍,实时在线代码高亮显示,它不是某个富文本编辑器的附属产品,它是许多大名鼎鼎的在线代码编辑器的基础库。
2.codemirror用法
var editor = CodeMirror.fromTextArea(document.getElementById("htmlEdit"), {
lineNumbers: false,
mode: "htmlmixed",
indentUnit: 2,
lineWrapping:true,
styleActiveLine: true
});
3.codemirror配置项
cmOptions: {
// codemirror config
flattenSpans: false, // 默认情况下,CodeMirror会将使用相同class的两个span合并成一个。通过设置此项为false禁用此功能
tabSize: 2, // tab缩进空格数
mode: '', // 模式
theme: 'monokai', // 主题
smartIndent: true, // 是否智能缩进
lineNumbers: true, // 显示行号
matchBrackets: true, // 匹配符号
lineWiseCopyCut: true, // 如果在复制或剪切时没有选择文本,那么就会自动操作光标所在的整行
indentWithTabs: true, // 在缩进时,是否需要把 n*tab宽度个空格替换成n个tab字符
electricChars: true, // 在输入可能改变当前的缩进时,是否重新缩进
indentUnit: 2, // 缩进单位,默认2
autoCloseTags: true, // 自动关闭标签
autoCloseBrackets: true, // 自动输入括弧
foldGutter: true, // 允许在行号位置折叠
cursorHeight: 1, // 光标高度
keyMap: 'sublime', // 快捷键集合
extraKeys: {
'Ctrl-Alt': 'autocomplete',
'Ctrl-Q': cm => {
cm.foldCode(cm.getCursor())
}
}, //智能提示
gutters: ['CodeMirror-linenumbers', 'CodeMirror-foldgutter'], // 用来添加额外的gutter
styleActiveLine: true // 激活当前行样式
},
“js代码在线运行的方法”的内容就介绍到这里了,感谢大家的阅读。如果想了解更多行业相关的知识可以关注天达云网站,小编将为大家输出更多高质量的实用文章!