我想在codemirror中使用htmlmixed模式。我开始在codemirror API中搜索,但我找不到它。我包括以下内容:
<script src="cm/lib/codemirror.js"></script>
<link rel="stylesheet" href="cm/lib/codemirror.css">
<script src="cm/mode/htmlmixed/htmlmixed.js"></script>
这是我的代码:
MCM = CodeMirror(JY.get("devroot"), {
mode: "htmlmixed",
value: "<p>Hello</p>"
});
但它不起作用。有人知道吗?
答案 0 :(得分:4)
您还必须包含模式脚本cm/mode/xml/xml.js
,cm/mode/javascript/javascript.js
和cm/mode/css/css.js
,它们是htmlmixed模式的依赖项。
答案 1 :(得分:0)
@Marjin给出了正确答案。但是完整的代码将如下所示:
<script src="/js/codemirror/lib/codemirror.js"></script>
<link rel="stylesheet" href="/js/codemirror/lib/codemirror.css">
<script src="/js/codemirror/mode/xml/xml.js"></script>
<script src="/js/codemirror/mode/javascript/javascript.js"></script>
<script src="/js/codemirror/mode/css/css.js"></script>
<script src="/js/codemirror/mode/htmlmixed/htmlmixed.js"></script>
<div class="page-wrap-editor">
<h3 class="editor-head">HTML код</h3>
<textarea id="ta"></textarea>
</div>
<script>
const ta = document.getElementById(`ta`);
const editor = CodeMirror.fromTextArea(ta, {
lineNumbers: true,
mode: "htmlmixed",
value: "<p>Hello</p>"
});
</script>