@@ -144,7 +144,7 @@ module.exports = {
144
144
'text/turtle' : true ,
145
145
'application/rdf+xml' : true ,
146
146
'application/xhtml+xml' : true , // For RDFa?
147
- // 'text/html': true,
147
+ 'text/html' : true , // For data island
148
148
// 'application/sparql-update': true,
149
149
'application/json' : true ,
150
150
'application/ld+json' : true
@@ -157,8 +157,11 @@ module.exports = {
157
157
* @param {Integer } caretPos - the poisition starting at zero
158
158
* @credit https://stackoverflow.com/questions/512528/set-keyboard-caret-position-in-html-textbox
159
159
*/
160
- function setCaretPosition ( elem , caretPos ) {
160
+ function setCaretPosition ( elem , cause ) {
161
161
if ( elem != null ) {
162
+ if ( cause . characterInFile === - 1 && cause . lineNo ) cause . lineNo += 1
163
+ const pos = cause . lineNo ? elem . value . split ( '\n' , cause . lineNo ) . join ( '\n' ) . length : 0
164
+ let caretPos = pos + cause . characterInFile
162
165
if ( elem . createTextRange ) {
163
166
const range = elem . createTextRange ( )
164
167
range . move ( 'character' , caretPos )
@@ -172,16 +175,40 @@ module.exports = {
172
175
}
173
176
}
174
177
178
+ function HTMLDataIsland ( data ) {
179
+ let dataIslandContentType = ''
180
+ let dataIsland = ''
181
+ let pos = 0
182
+ const scripts = data . split ( '</script' )
183
+ if ( scripts && scripts . length ) {
184
+ for ( let script of scripts ) {
185
+ script = '<script' + script . split ( '<script' ) [ 1 ] + '</script>'
186
+ const RDFType = [ 'text/turtle' , 'text/n3' , 'application/ld+json' , 'application/rdf+xml' ]
187
+ const contentType = RDFType . find ( type => script . includes ( `type="${ type } "` ) )
188
+ if ( contentType ) {
189
+ dataIsland = script . replace ( / ^ < s c r i p t ( .* ?) > / gms, '' ) . replace ( / < \/ s c r i p t > $ / gms, '' )
190
+ dataIslandContentType = contentType
191
+ break
192
+ }
193
+ }
194
+ }
195
+ return [ dataIsland , dataIslandContentType ]
196
+ }
197
+
175
198
function checkSyntax ( data , contentType , base ) {
176
199
if ( ! parseable [ contentType ] ) return true // don't check things we don't understand
200
+ if ( contentType = 'text/html' ) {
201
+ [ data , contentType , pos ] = HTMLDataIsland ( data )
202
+ if ( ! contentType ) return true
203
+ }
177
204
try {
178
205
statusRow . innerHTML = ''
179
206
contentType === 'application/json' ? JSON . parse ( data ) : $rdf . parse ( data , kb , base , contentType )
180
207
} catch ( e ) {
181
208
statusRow . appendChild ( UI . widgets . errorMessageBlock ( dom , e ) )
182
209
for ( let cause = e ; ( cause = cause . cause ) ; cause ) {
183
210
if ( cause . characterInFile ) {
184
- setCaretPosition ( textArea , e . characterInFile )
211
+ setCaretPosition ( textArea , cause )
185
212
}
186
213
}
187
214
return false
0 commit comments