javascript - CodeMirror 不显示 HTML 模式
问题描述
我正在尝试在我的 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
模式取决于、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>
推荐阅读
- python - Python Selenium 没有给出预期的结果
- android - Firebase 实时数据库允许超级用户编辑子用户数据
- javascript - 获取 API - ReactJS 上的 ERR_ABORTED 415(不支持的媒体类型)
- spring - Vanilla SpringBoot 应用程序在 IntelliJ 中工作,但 `mvn compile` 失败
- python - 如何在 python 中将 eli5.show_weights 转换为数组/列表
- python - Python中的Hoare分区方案
- kotlin - lateinit 属性没有很快赋值?
- tensorflow - 密集层需要 1 个输入,但它接收到 2 个输入张量,我该如何更改
- r - R For循环函数返回NULL
- python - Keras 中的 ImageDataGenerator 使用 flow_from_dataframe