首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >CodeMirror不显示HTML模式

CodeMirror不显示HTML模式
EN

Stack Overflow用户
提问于 2018-11-23 19:39:33
回答 1查看 1.6K关注 0票数 1

我试图在我的web应用程序中使用CodeMirror模式,但是它不会突出显示模式"htmlmixed“的单词。我不明白到底出了什么问题。每个文件的路径都是正确的,因为我没有收到任何404错误。以下是我所做的:

代码语言:javascript
复制
<!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>

任何帮助都将不胜感激!

谢谢!

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2018-11-23 20:42:29

htmlmixed模式依赖于xmljavascriptcss模式。必须包括它们才能使htmlmixed工作。

下面是一个示例:

代码语言:javascript
复制
var editor = CodeMirror.fromTextArea(document.getElementById("editor"), {
  lineNumbers: true,
  mode:  "htmlmixed",
  htmlMode: true,
});
代码语言:javascript
复制
<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>

票数 3
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/53452168

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档