code mirror Java模式好像不行
Code mirror Java mode does not seem to work
我正在尝试使用 Codemirror,它在其他模式下工作正常。这是我的代码:
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html;charset=utf-8" />
<link href="codemirror.css" rel="stylesheet" />
<link
href="theme/ambiance.css"
rel="stylesheet"
/>
<script src="codemirror.js"></script>
<script src="mode/javascript/javascript.js"></script>
</head>
<body>
<textarea id="codepane">
function hello(){
}
</textarea
>
<script>
CodeMirror.fromTextArea(document.getElementById("codepane"), {
mode: "javascript",
indentWithTabs: true,
smartIndent: true,
lineNumbers: true,
lineWrapping: true,
matchBrackets: true,
autofocus: true,
theme: "ambiance",
});
</script>
</body>
</html>
这是我的输出:
我正在尝试将其更改为 Java 模式,但我无法在模式文件夹中找到 Java 模式
我知道我必须将模式更改为 mode: "text/x-java",
但它不起作用,因为 java 没有随附的模式 js 文件。我在这里遗漏了什么吗?
正如您在 Codemirror website, you can see that when we click on the Java
mode, it redirects us to c-like mode 中看到的那样。所以,你可以使用 c-like
模式 js 文件你的目的。
CodeMirror.fromTextArea(document.getElementById("codepane"), {
mode: "text/x-java",
indentWithTabs: true,
smartIndent: true,
lineNumbers: true,
lineWrapping: true,
matchBrackets: true,
autofocus: true,
theme: "ambiance",
});
<link href="https://cdnjs.cloudflare.com/ajax/libs/codemirror/5.58.3/codemirror.min.css" rel="stylesheet" />
<link href="https://cdnjs.cloudflare.com/ajax/libs/codemirror/5.58.3/theme/ambiance.min.css" rel="stylesheet" />
<script src="https://cdnjs.cloudflare.com/ajax/libs/codemirror/5.58.3/codemirror.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/codemirror/5.58.3/mode/clike/clike.min.js"></script>
<textarea id="codepane">
private class InnerClass {
public int zero() {
return 0;
}
}
</textarea>
注意 - 由于我不熟悉codemirror,可能会有一些错误,但上面的代码片段应该可以解决你的问题。
Edit - 您可以使用 "text/x-java"
作为模式并加载编辑代码段中给出的 click.js
以配置正确的语法突出显示。
我正在尝试使用 Codemirror,它在其他模式下工作正常。这是我的代码:
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html;charset=utf-8" />
<link href="codemirror.css" rel="stylesheet" />
<link
href="theme/ambiance.css"
rel="stylesheet"
/>
<script src="codemirror.js"></script>
<script src="mode/javascript/javascript.js"></script>
</head>
<body>
<textarea id="codepane">
function hello(){
}
</textarea
>
<script>
CodeMirror.fromTextArea(document.getElementById("codepane"), {
mode: "javascript",
indentWithTabs: true,
smartIndent: true,
lineNumbers: true,
lineWrapping: true,
matchBrackets: true,
autofocus: true,
theme: "ambiance",
});
</script>
</body>
</html>
这是我的输出:
我正在尝试将其更改为 Java 模式,但我无法在模式文件夹中找到 Java 模式
我知道我必须将模式更改为 mode: "text/x-java",
但它不起作用,因为 java 没有随附的模式 js 文件。我在这里遗漏了什么吗?
正如您在 Codemirror website, you can see that when we click on the Java
mode, it redirects us to c-like mode 中看到的那样。所以,你可以使用 c-like
模式 js 文件你的目的。
CodeMirror.fromTextArea(document.getElementById("codepane"), {
mode: "text/x-java",
indentWithTabs: true,
smartIndent: true,
lineNumbers: true,
lineWrapping: true,
matchBrackets: true,
autofocus: true,
theme: "ambiance",
});
<link href="https://cdnjs.cloudflare.com/ajax/libs/codemirror/5.58.3/codemirror.min.css" rel="stylesheet" />
<link href="https://cdnjs.cloudflare.com/ajax/libs/codemirror/5.58.3/theme/ambiance.min.css" rel="stylesheet" />
<script src="https://cdnjs.cloudflare.com/ajax/libs/codemirror/5.58.3/codemirror.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/codemirror/5.58.3/mode/clike/clike.min.js"></script>
<textarea id="codepane">
private class InnerClass {
public int zero() {
return 0;
}
}
</textarea>
注意 - 由于我不熟悉codemirror,可能会有一些错误,但上面的代码片段应该可以解决你的问题。
Edit - 您可以使用 "text/x-java"
作为模式并加载编辑代码段中给出的 click.js
以配置正确的语法突出显示。