gpt4 book ai didi

javascript - CodeMirror 不显示 HTML 模式

转载 作者:行者123 更新时间:2023-11-28 14:36:19 24 4
gpt4 key购买 nike

我正在尝试在我的 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>

如有任何帮助,我们将不胜感激!

谢谢!

最佳答案

htmlmixed 模式依赖于xmljavascriptcss 模式。必须包含它们才能使 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">&lt;p&gt; I am HTML&lt;/p&gt;
&lt;script&gt;
console.log(&quot;I am JS&quot;);
&lt;/script&gt;</textarea>
</html>

关于javascript - CodeMirror 不显示 HTML 模式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53452168/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com