如何通过代码镜像启用htmlmixed模式

How to enable htmlmixed mode by codemirror?

本文关键字:htmlmixed 模式 启用 镜像 何通过 代码      更新时间:2023-09-26

我想要模式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>"
});

但是它不起作用。有人知道吗?

还必须包含模式脚本cm/mode/xml/xml.js, cm/mode/javascript/javascript.jscm/mode/css/css.js,它们是htmlmixed模式的依赖项。

@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>