我试图在我的web应用程序中使用CodeMirror模式,但是它不会突出显示模式"htmlmixed“的单词。我不明白到底出了什么问题。每个文件的路径都是正确的,因为我没有收到任何404错误。以下是我所做的:
<!DOCTYPE html>
<head>
<script src="/node_modules/codemirror/lib/codemirror.js"></script>
<link rel="stylesheet" href="/path-to/codemirror/lib/codemirror.css">
<script src="/path-to/codemirror/lib/codemirror.js"></script>
<script src="/path-to/codemirror/mode/htmlmixed/htmlmixed.js"></script>
<script src="/path-to/jquery.min.js"></script>
</head>
<html>
<textarea id="editor"></textarea>
....
</html>
<script>
var editor = CodeMirror.fromTextArea(document.getElementById("editor"), {
lineNumbers: true,
mode: "htmlmixed",
htmlMode: true,
});
</script>任何帮助都将不胜感激!
谢谢!
发布于 2018-11-23 20:42:29
htmlmixed模式依赖于xml、javascript和css模式。必须包括它们才能使htmlmixed工作。
下面是一个示例:
var editor = CodeMirror.fromTextArea(document.getElementById("editor"), {
lineNumbers: true,
mode: "htmlmixed",
htmlMode: true,
});<head>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/codemirror/5.41.0/codemirror.css" />
<script src="https://cdnjs.cloudflare.com/ajax/libs/codemirror/5.41.0/codemirror.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/codemirror/5.41.0/mode/htmlmixed/htmlmixed.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/codemirror/5.41.0/mode/xml/xml.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/codemirror/5.41.0/mode/javascript/javascript.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/codemirror/5.41.0/mode/css/css.js"></script>
</head>
<html>
<textarea id="editor"><p> I am HTML</p>
<script>
console.log("I am JS");
</script></textarea>
</html>
https://stackoverflow.com/questions/53452168
复制相似问题