CodeMirror:XML 代码未缩进
CodeMirror: XML code not being indented
我正在使用 CodeMirror 在 XML 模式下显示 XML,但代码没有自动缩进。
我检查过 XML 模式确实实现了 indent(state, textAfter, fullLine)
,它处理缩进,所以它应该可以工作。
这是我初始化 CodeMirror 的方式:
CodeMirror.fromTextArea(document.getElementById("test"), {
mode: 'application/xml',
theme: 'eclipse',
lineNumbers: true,
lineWrapping: true,
readOnly: true,
cursorBlinkRate: -1
});
查看此 jsFiddle link 的实时版本:https://jsfiddle.net/zrosfz7x。
有什么想法吗?
为了提供解决方案,我为 xml 添加了一个外部美化器。
这是一个完整的工作示例。
<html>
<head>
<meta charset="UTF-8">
<link rel=stylesheet href="//codemirror.net/lib/codemirror.css">
<script src=//codemirror.net/lib/codemirror.js></script>
<script src=//codemirror.net/mode/xml/xml.js></script>
<script src="//cdn.rawgit.com/vkiryukhin/vkBeautify/master/vkbeautify.js"></script>
</head>
<body>
<textarea id="test"><?xml version="1.0" encoding="UTF-8" ?><note><to>Tove</to><from>Jani</from><heading>Reminder</heading><body>Don't forget me this weekend!</body></note></textarea>
<script>
document.getElementById("test").value = vkbeautify.xml(document.getElementById("test").value);
CodeMirror.fromTextArea(document.getElementById("test"), {
mode: 'application/xml',
// theme: 'eclipse',
lineNumbers: true,
lineWrapping: true,
readOnly: true,
cursorBlinkRate: -1
});
</script>
</body>
</html>
这里还有更新的 jsFiddle:http://jsfiddle.net/zrosfz7x/3/
我正在使用 CodeMirror 在 XML 模式下显示 XML,但代码没有自动缩进。
我检查过 XML 模式确实实现了 indent(state, textAfter, fullLine)
,它处理缩进,所以它应该可以工作。
这是我初始化 CodeMirror 的方式:
CodeMirror.fromTextArea(document.getElementById("test"), {
mode: 'application/xml',
theme: 'eclipse',
lineNumbers: true,
lineWrapping: true,
readOnly: true,
cursorBlinkRate: -1
});
查看此 jsFiddle link 的实时版本:https://jsfiddle.net/zrosfz7x。
有什么想法吗?
为了提供解决方案,我为 xml 添加了一个外部美化器。 这是一个完整的工作示例。
<html>
<head>
<meta charset="UTF-8">
<link rel=stylesheet href="//codemirror.net/lib/codemirror.css">
<script src=//codemirror.net/lib/codemirror.js></script>
<script src=//codemirror.net/mode/xml/xml.js></script>
<script src="//cdn.rawgit.com/vkiryukhin/vkBeautify/master/vkbeautify.js"></script>
</head>
<body>
<textarea id="test"><?xml version="1.0" encoding="UTF-8" ?><note><to>Tove</to><from>Jani</from><heading>Reminder</heading><body>Don't forget me this weekend!</body></note></textarea>
<script>
document.getElementById("test").value = vkbeautify.xml(document.getElementById("test").value);
CodeMirror.fromTextArea(document.getElementById("test"), {
mode: 'application/xml',
// theme: 'eclipse',
lineNumbers: true,
lineWrapping: true,
readOnly: true,
cursorBlinkRate: -1
});
</script>
</body>
</html>
这里还有更新的 jsFiddle:http://jsfiddle.net/zrosfz7x/3/