@@ -201,6 +201,7 @@ export function buildMarkedConfiguration(markedOptions) {
201201 markedOptions . useNewRenderer = true ;
202202 const a_href_regex =
203203 / ( ( < a [ ^ > ] * ? h r e f = " ) ( [ ^ " ] * ?) ( " [ ^ > ] * ?> ) | ( < a [ ^ > ] * ? h r e f = ' ) ( [ ^ ' ] + ?) ( ' [ ^ > ] * ?> ) ) / gi;
204+ // TODO: apply img src also to data-preview-image
204205 const img_src_regex =
205206 / ( ( < i m g [ ^ > ] * ? s r c = " ) ( [ ^ " ] * ?) ( " [ ^ > ] * ?> ) | ( < i m g [ ^ > ] * ? s r c = ' ) ( [ ^ ' ] + ?) ( ' [ ^ > ] * ?> ) ) / gi;
206207 // const isUrl = /^https?:\/\//
@@ -220,15 +221,23 @@ export function buildMarkedConfiguration(markedOptions) {
220221 let last_index = 0 ;
221222 let remainder = "" ;
222223 for ( const match of token . text . matchAll ( img_src_regex ) ) {
223- const matchOffset = match [ 2 ] ? 0 : 3
224+ const matchOffset = match [ 2 ] ? 0 : 3 ;
224225 text . push ( token . text . substring ( last_index , match . index ) ) ;
225226 const ref = match [ 3 + matchOffset ] ;
226227 // const needsRebase = !(isUrl.test(ref) || isAbsolute.test(ref) || isLocal.test(ref))
227228 const needsRebase = isRelative . test ( ref ) ;
228229 if ( needsRebase ) {
229- text . push ( `${ match [ 2 + matchOffset ] } ${ base_url } ${ match [ 3 + matchOffset ] } ${ match [ 4 + matchOffset ] } ` ) ;
230+ text . push (
231+ `${ match [ 2 + matchOffset ] } ${ base_url } ${ match [ 3 + matchOffset ] } ${
232+ match [ 4 + matchOffset ]
233+ } `,
234+ ) ;
230235 } else {
231- text . push ( `${ match [ 2 + matchOffset ] } ${ match [ 3 + matchOffset ] } ${ match [ 4 + matchOffset ] } ` ) ;
236+ text . push (
237+ `${ match [ 2 + matchOffset ] } ${ match [ 3 + matchOffset ] } ${
238+ match [ 4 + matchOffset ]
239+ } `,
240+ ) ;
232241 }
233242 last_index = match . index + match [ 0 ] . length ;
234243 }
@@ -240,14 +249,22 @@ export function buildMarkedConfiguration(markedOptions) {
240249 last_index = 0 ;
241250 for ( const match of token . text . matchAll ( a_href_regex ) ) {
242251 text . push ( token . text . substring ( last_index , match . index ) ) ;
243- const matchOffset = match [ 2 ] ? 0 : 3
252+ const matchOffset = match [ 2 ] ? 0 : 3 ;
244253 const ref = match [ 3 + matchOffset ] ;
245254 // const needsRebase = !(isUrl.test(ref) || isAbsolute.test(ref) || isLocal.test(ref))
246255 const needsRebase = isRelative . test ( ref ) ;
247256 if ( needsRebase ) {
248- text . push ( `${ match [ 2 + matchOffset ] } ${ base_url } ${ match [ 3 + matchOffset ] } ${ match [ 4 + matchOffset ] } ` ) ;
257+ text . push (
258+ `${ match [ 2 + matchOffset ] } ${ base_url } ${ match [ 3 + matchOffset ] } ${
259+ match [ 4 + matchOffset ]
260+ } `,
261+ ) ;
249262 } else {
250- text . push ( `${ match [ 2 + matchOffset ] } ${ match [ 3 + matchOffset ] } ${ match [ 4 + matchOffset ] } ` ) ;
263+ text . push (
264+ `${ match [ 2 + matchOffset ] } ${ match [ 3 + matchOffset ] } ${
265+ match [ 4 + matchOffset ]
266+ } `,
267+ ) ;
251268 }
252269 last_index = match . index + match [ 0 ] . length ;
253270 }
@@ -265,19 +282,21 @@ export function buildMarkedConfiguration(markedOptions) {
265282 `<li class="fragment">${ text } </li>` ;
266283 }
267284 marked . use ( markedConfig ) ;
268- return marked
285+ return marked ;
269286}
270287
271288function codeHandler ( code , language ) {
272289 if ( language === "mermaid" ) {
273290 // INFO: height and width are set to work around bug https://github.com/chartjs/Chart.js/issues/5805
274291 DIAGRAM_COUNTER += 1 ;
275- return `<div data-mermaid-id="mermaid-${ DIAGRAM_COUNTER } " data-mermaid="${ btoa ( code )
276- } "></div>`;
292+ return `<div data-mermaid-id="mermaid-${ DIAGRAM_COUNTER } " data-mermaid="${
293+ btoa ( code )
294+ } "></div>`;
277295 } else if ( language === "chartjs" ) {
278296 // INFO: maybe set height and width are to work around bug https://github.com/chartjs/Chart.js/issues/5805
279- return `<div><div style="display: flex; align-items: center; justify-content: center; position: relative; width: 100%; height: 100%;"><canvas data-chartjs=${ btoa ( code )
280- } ></canvas></div></div>`;
297+ return `<div><div style="display: flex; align-items: center; justify-content: center; position: relative; width: 100%; height: 100%;"><canvas data-chartjs=${
298+ btoa ( code )
299+ } ></canvas></div></div>`;
281300 } else if (
282301 language === "apexchart"
283302 ) {
@@ -286,7 +305,7 @@ function codeHandler(code, language) {
286305 } else {
287306 return SANITIZE ( defaultCodeHandler ( code , language ) ) ;
288307 }
289- } ;
308+ }
290309
291310/**
292311 * Converts any current data-markdown slides in the
@@ -302,7 +321,7 @@ export function convertMarkdownToSlides(startElement, marked) {
302321 let sectionNumber = 0 ;
303322 const promises = [ ] ;
304323 [ ] . slice . call ( sections ) . forEach ( ( section ) => {
305- const parse = async function ( section ) {
324+ const parse = async function ( section ) {
306325 section . setAttribute ( "data-markdown-parsed" , true ) ;
307326 const notes = section . querySelector ( "aside.notes" ) ;
308327 const markdown = getMarkdownFromSlide ( section ) ;
@@ -320,11 +339,11 @@ export function convertMarkdownToSlides(startElement, marked) {
320339 section ,
321340 null ,
322341 section . getAttribute ( "data-element-attributes" ) ||
323- section . parentNode . getAttribute ( "data-element-attributes" ) ||
324- DEFAULT_ELEMENT_ATTRIBUTES_SEPARATOR ,
342+ section . parentNode . getAttribute ( "data-element-attributes" ) ||
343+ DEFAULT_ELEMENT_ATTRIBUTES_SEPARATOR ,
325344 section . getAttribute ( "data-attributes" ) ||
326- section . parentNode . getAttribute ( "data-attributes" ) ||
327- DEFAULT_SLIDE_ATTRIBUTES_SEPARATOR ,
345+ section . parentNode . getAttribute ( "data-attributes" ) ||
346+ DEFAULT_SLIDE_ATTRIBUTES_SEPARATOR ,
328347 ) ;
329348 // If there were notes, we need to re-add them after
330349 // having overwritten the section's HTML
@@ -421,7 +440,10 @@ function getMarkdownFromSlide(section) {
421440 // strip leading whitespace so it isn't evaluated as code
422441 let markdown = ( template || section ) . textContent ;
423442 // restore script end tags
424- markdown = markdown . replace ( new RegExp ( SCRIPT_END_PLACEHOLDER , "g" ) , "</script>" ) ;
443+ markdown = markdown . replace (
444+ new RegExp ( SCRIPT_END_PLACEHOLDER , "g" ) ,
445+ "</script>" ,
446+ ) ;
425447 const leadingWs = markdown . match ( / ^ \n ? ( \s * ) / ) [ 1 ] . length ,
426448 leadingTabs = markdown . match ( / ^ \n ? ( \t * ) / ) [ 1 ] . length ;
427449 if ( leadingTabs > 0 ) {
@@ -430,7 +452,10 @@ function getMarkdownFromSlide(section) {
430452 "\n" ,
431453 ) ;
432454 } else if ( leadingWs > 1 ) {
433- markdown = markdown . replace ( new RegExp ( "\\n? {" + leadingWs + "}" , "g" ) , "\n" ) ;
455+ markdown = markdown . replace (
456+ new RegExp ( "\\n? {" + leadingWs + "}" , "g" ) ,
457+ "\n" ,
458+ ) ;
434459 }
435460 return markdown ;
436461}
@@ -439,8 +464,8 @@ function getMarkdownFromSlide(section) {
439464 * Hide customcontrols if visibility of controls changes.
440465 */
441466function hideCustomControlsIfVisiblityChanges ( element ) {
442- const observer = new MutationObserver ( function ( mutations ) {
443- mutations . forEach ( function ( mutation ) {
467+ const observer = new MutationObserver ( function ( mutations ) {
468+ mutations . forEach ( function ( mutation ) {
444469 const style = window . getComputedStyle ( mutation . target , null ) ;
445470 const display = style ?. getPropertyValue ( "display" ) ;
446471 if ( display === "none" ) {
@@ -464,15 +489,15 @@ function hideCustomControlsIfVisiblityChanges(element) {
464489}
465490
466491function loadExternalMarkdown ( section ) {
467- return new Promise ( function ( resolve , reject ) {
492+ return new Promise ( function ( resolve , reject ) {
468493 const xhr = new XMLHttpRequest ( ) ;
469494 const url = section . getAttribute ( "data-markdown" ) ;
470495 const datacharset = section . getAttribute ( "data-charset" ) ;
471496 // see https://developer.mozilla.org/en-US/docs/Web/API/element.getAttribute#Notes
472497 if ( datacharset != null && datacharset != "" ) {
473498 xhr . overrideMimeType ( "text/html; charset=" + datacharset ) ;
474499 }
475- xhr . onreadystatechange = function ( _section , xhr ) {
500+ xhr . onreadystatechange = function ( _section , xhr ) {
476501 if ( xhr . readyState === XMLHttpRequest . DONE ) {
477502 // file protocol yields status code 0 (useful for local debug, mobile applications etc.)
478503 if ( ( xhr . status >= 200 && xhr . status < 300 ) || xhr . status === 0 ) {
@@ -488,8 +513,8 @@ function loadExternalMarkdown(section) {
488513 } catch ( e ) {
489514 console . warn (
490515 "Failed to get the Markdown file " + url +
491- ". Make sure that the presentation and the file are served by a HTTP server and the file can be found there. " +
492- e ,
516+ ". Make sure that the presentation and the file are served by a HTTP server and the file can be found there. " +
517+ e ,
493518 ) ;
494519 resolve ( xhr , url ) ;
495520 }
@@ -538,7 +563,7 @@ async function preProcessMarkdown(section, markdown) {
538563 notesSeparator : section . getAttribute ( "data-separator-notes" ) ,
539564 attributes : getForwardedAttributes ( section ) ,
540565 } ) ;
541- return metadata
566+ return metadata ;
542567}
543568
544569/**
@@ -554,17 +579,20 @@ export function preProcessSlides(scope) {
554579 scope . querySelectorAll (
555580 "section[data-markdown]:not([data-markdown-parsed])" ,
556581 ) ,
557- ) . forEach ( function ( section , _i ) {
582+ ) . forEach ( function ( section , _i ) {
558583 if ( section . getAttribute ( "data-markdown" ) === "<<load-plain-markdown>>" ) {
559584 // Directly parse markdown from an attribute that stores the markdown content
560585 externalPromises . push (
561- preProcessMarkdown ( section , section . getAttribute ( "data-markdown-plain" ) ) ,
586+ preProcessMarkdown (
587+ section ,
588+ section . getAttribute ( "data-markdown-plain" ) ,
589+ ) ,
562590 ) ;
563591 } else if ( section . getAttribute ( "data-markdown" ) . length ) {
564592 // Load external markdown from a URL that's provided in the data-markdown attriute and then parse it
565593 const promise = loadExternalMarkdown ( section ) . then (
566594 // Finished loading external file
567- function ( xhr , _url ) {
595+ function ( xhr , _url ) {
568596 if ( ! BASE_URL ) {
569597 // TODO: add support for multiple markdown elements
570598 const base_url = new URL ( xhr . responseURL ) ;
@@ -580,7 +608,7 @@ export function preProcessSlides(scope) {
580608 return preProcessMarkdown ( section , xhr . responseText ) ;
581609 } ,
582610 // Failed to load markdown
583- function ( xhr , url ) {
611+ function ( xhr , url ) {
584612 section . outerHTML = '<section data-state="alert">' +
585613 "ERROR: The attempt to fetch " + url +
586614 " failed with HTTP status " + xhr . status + "." +
@@ -595,19 +623,20 @@ export function preProcessSlides(scope) {
595623 const promise = slidify (
596624 getMarkdownFromSlide ( section ) . then ( ( res ) => {
597625 section . outerHTML = res ;
598- } ) , {
599- separator : section . getAttribute ( "data-separator" ) ,
600- verticalSeparator : section . getAttribute ( "data-separator-vertical" ) ,
601- notesSeparator : section . getAttribute ( "data-separator-notes" ) ,
602- attributes : getForwardedAttributes ( section ) ,
603- }
626+ } ) ,
627+ {
628+ separator : section . getAttribute ( "data-separator" ) ,
629+ verticalSeparator : section . getAttribute ( "data-separator-vertical" ) ,
630+ notesSeparator : section . getAttribute ( "data-separator-notes" ) ,
631+ attributes : getForwardedAttributes ( section ) ,
632+ } ,
604633 ) ;
605634 externalPromises . push ( promise ) ;
606635 }
607636 } ) ;
608- return Promise . all ( externalPromises ) . then ( metadatas => {
637+ return Promise . all ( externalPromises ) . then ( ( metadatas ) => {
609638 // Collect metadata in an object. The last value overwrites the first.
610- return metadatas . reduce ( ( acc , v ) => Object . assign ( acc , v ) , { } )
639+ return metadatas . reduce ( ( acc , v ) => Object . assign ( acc , v ) , { } ) ;
611640 } ) ;
612641}
613642
@@ -621,10 +650,10 @@ function slidify(markdown, options) {
621650 options = addSlidifyDefaultOptions ( options ) ;
622651 // FIXME: migrate these separators into custom marked parser to get away from regexp
623652 const separatorRegex = new RegExp (
624- options . separator +
625- ( options . verticalSeparator ? "|" + options . verticalSeparator : "" ) ,
626- "mg" ,
627- ) ,
653+ options . separator +
654+ ( options . verticalSeparator ? "|" + options . verticalSeparator : "" ) ,
655+ "mg" ,
656+ ) ,
628657 horizontalSeparatorRegex = new RegExp ( options . separator ) ,
629658 verticalSeparatorRegex = new RegExp (
630659 options . verticalSeparator ? "|" + options . verticalSeparator : "" ,
@@ -678,22 +707,28 @@ function slidify(markdown, options) {
678707 // vertical
679708 if ( sectionStack [ i ] instanceof Array ) {
680709 const section_promises = [ ] ;
681- sectionStack [ i ] . forEach ( function ( child ) {
710+ sectionStack [ i ] . forEach ( function ( child ) {
682711 section_promises . push (
683- createMarkdownSlide ( child , options ) . then ( ( content ) => "<section data-markdown>" + content + "</section>" ) ,
712+ createMarkdownSlide ( child , options ) . then ( ( content ) =>
713+ "<section data-markdown>" + content + "</section>"
714+ ) ,
684715 ) ;
685716 } ) ;
686717 promises . push (
687718 new Promise ( ( resolve ) => {
688719 Promise . all ( section_promises ) . then ( ( res ) =>
689- resolve ( "<section " + options . attributes + ">" + res . join ( "" ) + "</section>" )
720+ resolve (
721+ "<section " + options . attributes + ">" + res . join ( "" ) +
722+ "</section>" ,
723+ )
690724 ) ;
691725 } ) ,
692726 ) ;
693727 } else {
694728 promises . push (
695729 createMarkdownSlide ( sectionStack [ i ] , options ) . then ( ( content ) =>
696- "<section " + options . attributes + " data-markdown>" + content + "</section>"
730+ "<section " + options . attributes + " data-markdown>" + content +
731+ "</section>"
697732 ) ,
698733 ) ;
699734 }
@@ -777,7 +812,11 @@ const Plugin = () => {
777812 "copyright" : addMeta ( "copyright" ) ,
778813 "coverage" : addMeta ( "coverage" ) ,
779814 "date" : addMeta ( "dcterms.date" ) ,
780- "description" : desc => S . map ( fn => fn ( desc ) ) ( [ addMeta ( "description" ) , addMeta ( "og:description" ) ] ) ,
815+ "description" : ( desc ) =>
816+ S . map ( ( fn ) => fn ( desc ) ) ( [
817+ addMeta ( "description" ) ,
818+ addMeta ( "og:description" ) ,
819+ ] ) ,
781820 "designer" : addMeta ( "designer" ) ,
782821 "directory" : addMeta ( "directory" ) ,
783822 "distribution" : addMeta ( "distribution" ) ,
@@ -795,7 +834,8 @@ const Plugin = () => {
795834 "subject" : addMeta ( "subject" ) ,
796835 "summary" : addMeta ( "summary" ) ,
797836 "topic" : addMeta ( "topic" ) ,
798- "url" : url => S . map ( fn => fn ( url ) ) ( [ addMeta ( "url" ) , addMeta ( "og:url" ) ] ) ,
837+ "url" : ( url ) =>
838+ S . map ( ( fn ) => fn ( url ) ) ( [ addMeta ( "url" ) , addMeta ( "og:url" ) ] ) ,
799839 "fontawesomePro" : loadScript (
800840 "https://kit.fontawesome.com/fec85b2437.js" ,
801841 "anonymous" ,
@@ -832,7 +872,10 @@ const Plugin = () => {
832872 } else {
833873 if ( typeof value === "string" ) {
834874 // strip quotes and whitespace
835- return value . replaceAll ( / ( ^ [ \t ] * [ \' \" ] ? [ \t ] * ) | ( [ \t ] * [ \' \" ] ? [ \t ] * $ ) / g, '' ) ;
875+ return value . replaceAll (
876+ / ( ^ [ \t ] * [ \' \" ] ? [ \t ] * ) | ( [ \t ] * [ \' \" ] ? [ \t ] * $ ) / g,
877+ "" ,
878+ ) ;
836879 } else {
837880 return value ;
838881 }
@@ -903,10 +946,9 @@ const Plugin = () => {
903946 * Starts processing and converting Markdown within the
904947 * current reveal.js deck.
905948 */
906- init : function ( reveal ) {
907- deck = reveal
908- let { renderer, ...markedOptions } =
909- deck . getConfig ( ) . markdown || { } ;
949+ init : function ( reveal ) {
950+ deck = reveal ;
951+ let { renderer, ...markedOptions } = deck . getConfig ( ) . markdown || { } ;
910952
911953 deck . on ( "ready" , ( _event ) => {
912954 hideCustomControlsIfVisiblityChanges (
@@ -922,7 +964,7 @@ const Plugin = () => {
922964 // 3. convertMarkdownToSlides converts all markdown into HTML.
923965 // 4. Control his handed over to revealjs to display the slides.
924966 return preProcessSlides ( deck . getRevealElement ( ) ) . then ( ( metadata ) => {
925- this . marked = buildMarkedConfiguration ( markedOptions )
967+ this . marked = buildMarkedConfiguration ( markedOptions ) ;
926968 applyMetadata ( metadata ) ;
927969 return convertMarkdownToSlides ( deck . getRevealElement ( ) , this . marked ) ;
928970 } ) ;
0 commit comments