18
18
< link rel ="stylesheet " href ="static/css/bootstrap.min.css ">
19
19
< link rel ="stylesheet " href ="static/css/prettify.min.css ">
20
20
< link rel ="stylesheet " href ="static/css/jquery-confirm.min.css ">
21
+ < link rel ="stylesheet " type ="text/css " href ="https://codemirror.net/lib/codemirror.css ">
21
22
22
23
< script src ="static/js/jquery-3.2.1.min.js "> </ script >
24
+ < script src ="https://codemirror.net/lib/codemirror.js "> </ script >
23
25
< script src ="static/js/bootstrap.min.js "> </ script >
24
- < script src ="static/js/prettify.min.js "> </ script >
26
+ <!-- < script src="static/js/prettify.min.js"></script> -- >
25
27
< link rel ="stylesheet " type ="text/css " href ="static/css/animate3.5.2.min.css ">
26
28
27
29
< script src ="lib/parser.js "> </ script >
28
30
< script src ="static/js/jquery-confirm.min.js "> </ script >
31
+ < style >
32
+ .CodeMirror {
33
+ height : 100% ;
34
+ width : 100% ;
35
+ }
36
+ </ style >
29
37
</ head >
30
38
< body >
31
39
< body role ="document " style ="background-color: #2c3e50; ">
@@ -52,6 +60,7 @@ <h2>Note!!</h2>
52
60
</ div >
53
61
< div style ="border: 1px dashed grey; margin: 5px; padding: 5px; ">
54
62
< h2 > Parsing options</ h2 >
63
+ < p > < small > * Parser will not validate the XML</ small > </ p >
55
64
< input type ="checkbox " id ="attrNodeName "> Group all the attributes < br >
56
65
< input type ="checkbox " id ="ignoreAttributes " checked ="true "> Ignore attributes < br >
57
66
< input type ="checkbox " id ="ignoreNameSpace "> Remove namespace string from tag and attribute names. < br >
@@ -85,33 +94,75 @@ <h2>Validator options</h2>
85
94
</ div >
86
95
</ div >
87
96
< script src ="https://cdn.rawgit.com/nimndata/nimnjs-schema-builder/5a452c40/dist/nimn-schema-builder.js "> </ script >
97
+
88
98
< script >
99
+ var highlightedLine = null ;
100
+ var editor ;
101
+
102
+ function updateLength ( ) {
103
+ var xmlData = editor . getValue ( ) ;
104
+ $ ( "#lengthxml" ) [ 0 ] . innerText = xmlData . replace ( / > \s * < / g, "><" ) . length ;
105
+ }
106
+
107
+ function onChange ( ) {
108
+ highlightLine ( ) ;
109
+ updateLength ( ) ;
110
+ }
111
+ function highlightLine ( n ) {
112
+ if ( n ) {
113
+ unhighlightLine ( ) ;
114
+ highlightedLine = editor . addLineClass ( n - 1 , 'background' , 'alert-danger' ) ;
115
+ editor . setCursor ( n ) ;
116
+ } else {
117
+ unhighlightLine ( )
118
+ }
119
+ }
120
+
121
+ function unhighlightLine ( ) {
122
+ if ( highlightedLine ) {
123
+ editor . removeLineClass ( highlightedLine , 'background' , 'alert-danger' ) ;
124
+ highlightedLine = null ;
125
+ }
126
+ }
127
+
89
128
$ ( document ) . ready ( function ( ) {
90
129
//var parser = require("parser");
130
+ editor = CodeMirror . fromTextArea ( document . getElementById ( "txtXml" ) , {
131
+ mode : "application/xml" ,
132
+ styleActiveLine : true ,
133
+ lineNumbers : true ,
134
+ foldGutter : true ,
135
+ autofocus : true ,
136
+ gutters : [ "CodeMirror-foldgutter" ]
137
+ } ) ;
138
+
139
+ // when user types something, remove highlighting from "bad" line
140
+ editor . on ( 'change' , ( ) => onChange ( ) ) ;
141
+ editor . on ( 'drop' , ( ) => onChange ( ) ) ;
91
142
92
- $ ( '#txtXml' ) . on ( 'input' , function ( ) {
143
+ /* $('#txtXml').on('input', function(){
93
144
updateLength();
94
- } ) ;
145
+ }); */
95
146
96
147
$ ( '#toJson' ) . on ( 'click' , function ( ) {
97
148
$ ( '#result' ) . val ( '' ) ;
98
- var result = parser . parse ( $ ( '#txtXml' ) . val ( ) , buildParsingConfig ( ) ) ;
149
+ var result = parser . parse ( editor . getValue ( ) , buildParsingConfig ( ) ) ;
99
150
updateOutputLength ( JSON . stringify ( result ) ) ;
100
151
$ ( '#result' ) . val ( JSON . stringify ( result , null , 4 ) ) ;
101
152
} ) ;
102
153
103
154
$ ( '#toXml' ) . on ( 'click' , function ( ) {
104
- $ ( '#txtXml' ) . val ( '' ) ;
155
+ editor . setValue ( '' ) ;
105
156
var result = buildJ2XParser ( ) . parse ( JSON . parse ( $ ( '#result' ) . val ( ) ) ) ;
106
- $ ( '#txtXml' ) . val ( '<?xml version="1.0"?>\n' + result ) ;
157
+ editor . setValue ( '<?xml version="1.0"?>\n' + result ) ;
107
158
} ) ;
108
159
109
160
$ ( '#toNimn' ) . on ( 'click' , function ( ) {
110
161
$ ( '#result' ) . val ( '' ) ;
111
162
112
- var jsonData = parser . parse ( $ ( '#txtXml' ) . val ( ) , buildParsingConfig ( ) ) ;
163
+ var jsonData = parser . parse ( editor . getValue ( ) , buildParsingConfig ( ) ) ;
113
164
var schema = nimnSchemaBuilder . build ( jsonData ) ;
114
- var result = parser . parseToNimn ( $ ( '#txtXml' ) . val ( ) , schema , buildParsingConfig ( ) ) ;
165
+ var result = parser . parseToNimn ( editor . getValue ( ) , schema , buildParsingConfig ( ) ) ;
115
166
updateOutputLength ( result ) ;
116
167
$ ( '#result' ) . val ( result ) ;
117
168
} ) ;
@@ -122,10 +173,13 @@ <h2>Validator options</h2>
122
173
allowBooleanAttributes : $ ( "#allowBooleanAttributes_v" ) . prop ( "checked" ) ,
123
174
localeRange : $ ( "#localeRange_v" ) . val ( ) === "" ? "a-zA-Z" : $ ( "#cdataTagName" ) . val ( ) ,
124
175
} ;
125
- var val = parser . validate ( $ ( '#txtXml' ) . val ( ) , config ) ;
176
+ var val = parser . validate ( editor . getValue ( ) , config ) ;
126
177
if ( val === true ) {
127
178
$ ( '#result' ) . val ( "Valid XML" ) ;
128
179
} else {
180
+ if ( val . err . line ) {
181
+ highlightLine ( val . err . line ) ;
182
+ }
129
183
$ ( '#result' ) . val ( JSON . stringify ( val , null , 4 ) ) ;
130
184
}
131
185
} ) ;
@@ -184,16 +238,13 @@ <h2>Validator options</h2>
184
238
return ;
185
239
}
186
240
187
- function updateLength ( ) {
188
- var xmlData = $ ( '#txtXml' ) . val ( ) ;
189
- $ ( "#lengthxml" ) [ 0 ] . innerText = xmlData . replace ( / > \s * < / g, "><" ) . length ;
190
- }
241
+
191
242
192
243
function updateOutputLength ( data ) {
193
244
$ ( "#lengthoutput" ) [ 0 ] . innerText = data . length ;
194
245
}
195
246
196
- $ ( '#txtXml' ) . val ( `<?xml version="1.0"?>
247
+ editor . setValue ( `<?xml version="1.0"?>
197
248
<any_name>
198
249
<person>
199
250
<phone>+122233344550</phone>
@@ -240,5 +291,6 @@ <h2>Validator options</h2>
240
291
} ) ;
241
292
</ script >
242
293
< script async defer src ="https://buttons.github.io/buttons.js "> </ script >
294
+
243
295
</ body >
244
296
</ html >
0 commit comments