()
| 28 | }; |
| 29 | |
| 30 | const Plugin = () => { |
| 31 | |
| 32 | // The reveal.js instance this plugin is attached to |
| 33 | let deck; |
| 34 | let markedInstance = null; |
| 35 | |
| 36 | /** |
| 37 | * Retrieves the markdown contents of a slide section |
| 38 | * element. Normalizes leading tabs/whitespace. |
| 39 | */ |
| 40 | function getMarkdownFromSlide( section ) { |
| 41 | |
| 42 | // look for a <script> or <textarea data-template> wrapper |
| 43 | const template = section.querySelector( '[data-template]' ) || section.querySelector( 'script' ); |
| 44 | |
| 45 | // strip leading whitespace so it isn't evaluated as code |
| 46 | let text = ( template || section ).textContent; |
| 47 | |
| 48 | // restore script end tags |
| 49 | text = text.replace( new RegExp( SCRIPT_END_PLACEHOLDER, 'g' ), '</script>' ); |
| 50 | |
| 51 | const leadingWs = text.match( /^\n?(\s*)/ )[1].length, |
| 52 | leadingTabs = text.match( /^\n?(\t*)/ )[1].length; |
| 53 | |
| 54 | if( leadingTabs > 0 ) { |
| 55 | text = text.replace( new RegExp('\\n?\\t{' + leadingTabs + '}(.*)','g'), function(m, p1) { return '\n' + p1 ; } ); |
| 56 | } |
| 57 | else if( leadingWs > 1 ) { |
| 58 | text = text.replace( new RegExp('\\n? {' + leadingWs + '}(.*)', 'g'), function(m, p1) { return '\n' + p1 ; } ); |
| 59 | } |
| 60 | |
| 61 | return text; |
| 62 | |
| 63 | } |
| 64 | |
| 65 | /** |
| 66 | * Given a markdown slide section element, this will |
| 67 | * return all arguments that aren't related to markdown |
| 68 | * parsing. Used to forward any other user-defined arguments |
| 69 | * to the output markdown slide. |
| 70 | */ |
| 71 | function getForwardedAttributes( section ) { |
| 72 | |
| 73 | const attributes = section.attributes; |
| 74 | const result = []; |
| 75 | |
| 76 | for( let i = 0, len = attributes.length; i < len; i++ ) { |
| 77 | const name = attributes[i].name, |
| 78 | value = attributes[i].value; |
| 79 | |
| 80 | // disregard attributes that are used for markdown loading/parsing |
| 81 | if( /data\-(markdown|separator|vertical|notes)/gi.test( name ) ) continue; |
| 82 | |
| 83 | if( value ) { |
| 84 | result.push( name + '="' + value + '"' ); |
| 85 | } |
| 86 | else { |
| 87 | result.push( name ); |
nothing calls this directly
no test coverage detected
searching dependent graphs…