javascript - Code Beautification with angular-ui-codemirror with indention -


i generated xml code jquery using following code,

var _outerblock = $("<outerblock>");  (var = 0; < 10; i++) {    var _innerblock = $("<innerblock>serial " + + "</innerblock>")    _outerblock.append(_innerblock)  }  var _tmp = $("<div>");  var $output = _tmp.html();

now getting 1 line xml code in $output variable. tried using codemirror.js beautify code, applying styling not adding indention.

here tried browser console plain codemirror.js

var mycodemirror = codemirror(document.body, {   value: code,   mode:  "text/html",   linenumbers:true }); 

how can use indention? how can display code angular-ui-codemirror?

for correct xml syntax indentation need include

<script type="text/javascript" src="codemirror/mode/xml/xml.js"></script> 

(path xml mode js file may different, anyways need such defined..)

then use like:

config = {     mode : "xml",     htmlmode: true,     // ... }; 

..and in angular append ui-codemirror ever element need.

in angular, setup given though differently:

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

codemirror html mode not working

https://github.com/angular-ui/ui-codemirror/blob/master/readme.md


Comments

Popular posts from this blog

c# - Validate object ID from GET to POST -

node.js - Custom Model Validator SailsJS -

php - Find a regex to take part of Email -