I'm trying to get formatting right for the Ace (Ajax.org Cloud9 Editor) so I am parsing through the Json pulled from the @Model in an MVC view like so:
var model = JSON.stringify(@Html.Raw(Json.Encode(Model)));
var comma = model.replace(/,/g, ",\r\n");
var curlyBracket = comma.replace(/{/g, "{\r\n");
var colonCurlyBracket = bracket.replace(/:{/g, ':\r\n\{');
var bracketCurlyBracket = colonCurlyBracket.replace(/:\[{/g, ':\r\n\[{');
editor.setValue(bracketCurlyBracket, -1);
The problem is this doesn't do any indents to keep the formatting correct, it just puts carriage returns and new lines. I tried using:
var comma = model.replace(/,/g, ",\r\n\");
var curlyBracket = comma.replace(/{/g, "{\r\n\");
var colonCurlyBracket = bracket.replace(/:{/g, ':\r\n\\{');
var bracketCurlyBracket = colonCurlyBracket.replace(/:\[{/g, ':\r\n\\[{');
but the extra "\" gives me the error "Unterminated string constant" on the first two lines and on the second two lines it just adds a "\" to the editor. I need the lines to continue so that the indents get put in and the formatting works. How do I do this?