[英]Code Beautification with angular-ui-codemirror with indention
I generated xml code with jquery by using following code, 我使用以下代码通过jquery生成了xml代码,
var _outerBlock = $("<outerBlock>"); for (var i = 0; i < 10; i++) { var _innerBlock = $("<innerBlock>Serial " + i + "</innerBlock>") _outerBlock.append(_innerBlock) } var _tmp = $("<div>"); var $output = _tmp.html();
Now I am getting one line xml code in $output variable. 现在,我在$ output变量中获得了一行xml代码。 I tried using codemirror.js to beautify this code, its applying styling but it is not adding indention.
我尝试使用codemirror.js来美化此代码,并应用样式但未添加缩进。
Here What I tried from browser console with plain codemirror.js 这是我从浏览器控制台使用普通codemirror.js尝试的内容
var myCodeMirror = CodeMirror(document.body, {
value: code,
mode: "text/html",
lineNumbers:true
});
How Can I use indention? 如何使用缩进? How can I display code with angular-ui-codemirror?
如何使用angular-ui-codemirror显示代码?
For correct xml syntax indentation you need to include 为了正确的xml语法缩进,您需要包括
<script type="text/javascript" src="codemirror/mode/xml/xml.js"></script>
(path to xml mode js file may be different, but you anyways need such defined..) (到xml模式js文件的路径可能不同,但是无论如何您都需要这样定义。)
Then you use it like: 然后,您可以像这样使用它:
config = {
mode : "xml",
htmlMode: true,
// ...
};
..and in angular you append ui-codemirror to what ever element you need. ..and角,您将ui-codemirror附加到所需的任何元素。
In angular, setup is given though differently: 在angular中,设置方式有所不同:
myAppModule.controller('MyController', [ '$scope', function($scope) {
$scope.editorOptions = {
lineWrapping : true,
lineNumbers: true,
readOnly: 'nocursor',
mode: 'xml',
};
}]); }]);
.. And ..并且
<ui-codemirror ui-codemirror-opts="editorOptions"></ui-codemirror>
Sources / further reading: 资料来源/进一步阅读:
https://libraries.io/bower/angular-sdco-tools https://libraries.io/bower/angular-sdco-tools
CodeMirror HTML mode not working CodeMirror HTML模式不起作用
https://github.com/angular-ui/ui-codemirror/blob/master/README.md https://github.com/angular-ui/ui-codemirror/blob/master/README.md
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.