diff --git a/HISTORY.md b/HISTORY.md index 5108846..9a3172a 100644 --- a/HISTORY.md +++ b/HISTORY.md @@ -9,7 +9,8 @@ https://github.com/josdejong/jsoneditor - Implemented a status bar showing cursor location. Thanks @meirotstein. - Implemented repairing JSON objects containing left and right single - and double quotes (which you get when typing a JSON object in Word). + and double quotes (which you get when typing a JSON object in Word) + in `text` and `code` mode. ## 2017-09-16, version 5.9.6 diff --git a/src/css/img/jsoneditor-icons.svg b/src/css/img/jsoneditor-icons.svg index 1b40068..a085c2d 100644 --- a/src/css/img/jsoneditor-icons.svg +++ b/src/css/img/jsoneditor-icons.svg @@ -11,7 +11,7 @@ height="144" id="svg4136" version="1.1" - inkscape:version="0.91 r" + inkscape:version="0.91 r13725" sodipodi:docname="jsoneditor-icons.svg"> JSON Editor Icons @@ -39,12 +39,12 @@ inkscape:pageopacity="0" inkscape:pageshadow="2" inkscape:window-width="1920" - inkscape:window-height="1028" + inkscape:window-height="1027" id="namedview4144" showgrid="true" inkscape:zoom="4" - inkscape:cx="97.217248" - inkscape:cy="59.950227" + inkscape:cx="74.167308" + inkscape:cy="53.488549" inkscape:window-x="0" inkscape:window-y="0" inkscape:window-maximized="1" @@ -710,49 +710,49 @@ width="15.99999" y="101" x="76.000008" - style="fill:#ffffff;fill-opacity:0.80000007;stroke:none;stroke-width:0" /> + style="fill:#ffffff;fill-opacity:0.8;stroke:none;stroke-width:0" /> + style="fill:#ffffff;fill-opacity:0.8;stroke:none;stroke-width:0" /> + style="fill:#ffffff;fill-opacity:0.8;stroke:none;stroke-width:0" /> + style="fill:#ffffff;fill-opacity:0.8;stroke:none;stroke-width:0" /> + style="fill:#ffffff;fill-opacity:0.8;stroke:none;stroke-width:0" /> + style="fill:#ffffff;fill-opacity:0.8;stroke:none;stroke-width:0" /> + style="fill:#ffffff;fill-opacity:0.8;stroke:none;stroke-width:0" /> + diff --git a/src/css/menu.css b/src/css/menu.css index 6a4f44c..22a3923 100644 --- a/src/css/menu.css +++ b/src/css/menu.css @@ -71,6 +71,9 @@ div.jsoneditor-menu > button.jsoneditor-compact { div.jsoneditor-menu > button.jsoneditor-format { background-position: -72px -120px; } +div.jsoneditor-menu > button.jsoneditor-repair { + background-position: -96px -96px; +} div.jsoneditor-menu > div.jsoneditor-modes { display: inline-block; diff --git a/src/js/textmode.js b/src/js/textmode.js index 1d6fa21..761307c 100644 --- a/src/js/textmode.js +++ b/src/js/textmode.js @@ -136,6 +136,22 @@ textmode.create = function (container, options) { } }; + // create repair button + var buttonRepair = document.createElement('button'); + buttonRepair.type = 'button'; + buttonRepair.className = 'jsoneditor-repair'; + buttonRepair.title = 'Repair JSON data: fix quotes and escape characters, remove comments and JSONP notation.'; + this.menu.appendChild(buttonRepair); + buttonRepair.onclick = function () { + try { + me.repair(); + me._onChange(); + } + catch (err) { + me._onError(err); + } + }; + // create mode box if (this.options && this.options.modes && this.options.modes.length) { this.modeSwitcher = new ModeSwitcher(this.menu, this.options.modes, this.options.mode, function onSwitch(mode) { @@ -414,7 +430,7 @@ textmode.destroy = function () { }; /** - * Compact the code in the formatter + * Compact the code in the text editor */ textmode.compact = function () { var json = this.get(); @@ -423,7 +439,7 @@ textmode.compact = function () { }; /** - * Format the code in the formatter + * Format the code in the text editor */ textmode.format = function () { var json = this.get(); @@ -431,6 +447,15 @@ textmode.format = function () { this.setText(text); }; +/** + * Repair the code in the text editor + */ +textmode.repair = function () { + var text = this.getText(); + var sanitizedText = util.sanitize(text); + this.setText(sanitizedText); +}; + /** * Set focus to the formatter */