File tree Expand file tree Collapse file tree 3 files changed +26
-8
lines changed
indigo_app/static/javascript/indigo Expand file tree Collapse file tree 3 files changed +26
-8
lines changed Original file line number Diff line number Diff line change 64
64
* @param mutation MutationRecord
65
65
* @param element Element in this XML document
66
66
* @returns 'changed' if the mutation impacts the element, 'removed' if the element was removed from the tree,
67
+ * 'replaced', if the element has been replaced (with a node in mutation.addedNodes),
67
68
* or null if there is no impact
68
69
*/
69
70
getMutationImpact ( mutation , element ) {
98
99
let root = null ;
99
100
100
101
try {
101
- root = $ . parseXML ( newValue ) ;
102
+ root = Indigo . parseXml ( newValue ) ;
102
103
} catch ( e ) {
103
104
Indigo . errorView . show ( "The document has invalid XML." ) ;
104
105
return ;
Original file line number Diff line number Diff line change @@ -30,4 +30,19 @@ $(function() {
30
30
}
31
31
}
32
32
setTimeout ( nukeToasts , 3 * 1000 ) ;
33
+
34
+ /**
35
+ * Parses text into an XML document.
36
+ * @param text
37
+ * @returns {Document }
38
+ * @throws {Error } if the text is not valid XML
39
+ */
40
+ Indigo . parseXml = function ( text ) {
41
+ const parser = new DOMParser ( ) ;
42
+ const doc = parser . parseFromString ( text , "application/xml" ) ;
43
+ if ( doc . querySelector ( "parsererror" ) ) {
44
+ throw Error ( "Invalid XML: " + new XMLSerializer ( ) . serializeToString ( doc ) ) ;
45
+ }
46
+ return doc ;
47
+ }
33
48
} ) ;
Original file line number Diff line number Diff line change @@ -436,14 +436,16 @@ class XMLEditor {
436
436
onEditorChanged ( ) {
437
437
const text = this . editor . getValue ( ) . trim ( ) ;
438
438
if ( text ) {
439
- console . log ( 'Parsing changes to XML' ) ;
440
- const parser = new DOMParser ( ) ;
441
- const doc = parser . parseFromString ( text , "application/xml" ) ;
442
- if ( doc . querySelector ( "parsererror" ) ) {
443
- console . log ( "Invalid XML:" + new XMLSerializer ( ) . serializeToString ( doc ) ) ;
444
- } else {
445
- this . onElementParsed ( doc . documentElement ) ;
439
+ let doc ;
440
+ try {
441
+ console . log ( 'Parsing changes to XML' ) ;
442
+ doc = Indigo . parseXml ( text ) ;
443
+ } catch ( err ) {
444
+ // squash errors
445
+ console . log ( err ) ;
446
+ return ;
446
447
}
448
+ this . onElementParsed ( doc . documentElement ) ;
447
449
}
448
450
}
449
451
}
You can’t perform that action at this time.
0 commit comments