( section )
| 261 | } |
| 262 | |
| 263 | function loadExternalMarkdown( section ) { |
| 264 | |
| 265 | return new Promise( function( resolve, reject ) { |
| 266 | |
| 267 | const xhr = new XMLHttpRequest(), |
| 268 | url = section.getAttribute( 'data-markdown' ); |
| 269 | |
| 270 | const datacharset = section.getAttribute( 'data-charset' ); |
| 271 | |
| 272 | // see https://developer.mozilla.org/en-US/docs/Web/API/element.getAttribute#Notes |
| 273 | if( datacharset !== null && datacharset !== '' ) { |
| 274 | xhr.overrideMimeType( 'text/html; charset=' + datacharset ); |
| 275 | } |
| 276 | |
| 277 | xhr.onreadystatechange = function( section, xhr ) { |
| 278 | if( xhr.readyState === 4 ) { |
| 279 | // file protocol yields status code 0 (useful for local debug, mobile applications etc.) |
| 280 | if ( ( xhr.status >= 200 && xhr.status < 300 ) || xhr.status === 0 ) { |
| 281 | |
| 282 | resolve( xhr, url ); |
| 283 | |
| 284 | } |
| 285 | else { |
| 286 | |
| 287 | reject( xhr, url ); |
| 288 | |
| 289 | } |
| 290 | } |
| 291 | }.bind( this, section, xhr ); |
| 292 | |
| 293 | xhr.open( 'GET', url, true ); |
| 294 | |
| 295 | try { |
| 296 | xhr.send(); |
| 297 | } |
| 298 | catch ( e ) { |
| 299 | console.warn( 'Failed to get the Markdown file ' + url + '. Make sure that the presentation and the file are served by a HTTP server and the file can be found there. ' + e ); |
| 300 | resolve( xhr, url ); |
| 301 | } |
| 302 | |
| 303 | } ); |
| 304 | |
| 305 | } |
| 306 | |
| 307 | /** |
| 308 | * Check if a node value has the attributes pattern. |
no test coverage detected
searching dependent graphs…