MCPcopy
hub / github.com/hakimel/reveal.js / loadExternalMarkdown

Function loadExternalMarkdown

plugin/markdown/plugin.js:263–305  ·  view source on GitHub ↗
( section )

Source from the content-addressed store, hash-verified

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.

Callers 1

processSlidesFunction · 0.85

Calls 2

openMethod · 0.65
bindMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…