(function(l,u){typeof define=="function"&&define.amd?(l.marked=require("./marked"),l.RevealMarkdown=u(l.marked)):typeof exports=="object"?module.exports=u(require("./marked")):l.RevealMarkdown=u(l.marked)})(this,function(l){var u=`^\r?
---\r?
$`,k="notes?:",x="\\.element\\s*?(.+?)$",P="\\.slide:\\s*?(\\S.+?)$",v="__SCRIPT_END__";function f(a){var e=a.querySelector("[data-template]")||a.querySelector("script"),t=(e||a).textContent;t=t.replace(new RegExp(v,"g"),"<\/script>");var r=t.match(/^\n?(\s*)/)[1].length,i=t.match(/^\n?(\t*)/)[1].length;return i>0?t=t.replace(new RegExp("\\n?\\t{"+i+"}","g"),`
`):r>1&&(t=t.replace(new RegExp("\\n? {"+r+"}","g"),`
`)),t}function E(a){for(var e=a.attributes,t=[],r=0,i=e.length;r<i;r++){var n=e[r].name,s=e[r].value;/data\-(markdown|separator|vertical|notes)/gi.test(n)||(s?t.push(n+'="'+s+'"'):t.push(n))}return t.join(" ")}function b(a){return a=a||{},a.separator=a.separator||u,a.notesSeparator=a.notesSeparator||k,a.attributes=a.attributes||"",a}function p(a,e){e=b(e);var t=a.split(new RegExp(e.notesSeparator,"mgi"));return t.length===2&&(a=t[0]+'<aside class="notes">'+l(t[1].trim())+"</aside>"),a=a.replace(/<\/script>/g,v),'<script type="text/template">'+a+"<\/script>"}function g(a,e){e=b(e);for(var t=new RegExp(e.separator+(e.verticalSeparator?"|"+e.verticalSeparator:""),"mg"),r=new RegExp(e.separator),i,n=0,s,h=!0,m,d=[];i=t.exec(a);)notes=null,s=r.test(i[0]),!s&&h&&d.push([]),m=a.substring(n,i.index),s&&h?d.push(m):d[d.length-1].push(m),n=t.lastIndex,h=s;(h?d:d[d.length-1]).push(a.substring(n));for(var o="",c=0,M=d.length;c<M;c++)d[c]instanceof Array?(o+="<section "+e.attributes+">",d[c].forEach(function(N){o+="<section data-markdown>"+p(N,e)+"</section>"}),o+="</section>"):o+="<section "+e.attributes+" data-markdown>"+p(d[c],e)+"</section>";return o}function w(){return new Promise(function(a){var e=[];[].slice.call(document.querySelectorAll("[data-markdown]")).forEach(function(t,r){t.getAttribute("data-markdown").length?e.push(y(t).then(function(i,n){t.outerHTML=g(i.responseText,{separator:t.getAttribute("data-separator"),verticalSeparator:t.getAttribute("data-separator-vertical"),notesSeparator:t.getAttribute("data-separator-notes"),attributes:E(t)})},function(i,n){t.outerHTML='<section data-state="alert">ERROR: The attempt to fetch '+n+" failed with HTTP status "+i.status+".Check your browser's JavaScript console for more details.<p>Remember that you need to serve the presentation HTML from a HTTP server.</p></section>"})):t.getAttribute("data-separator")||t.getAttribute("data-separator-vertical")||t.getAttribute("data-separator-notes")?t.outerHTML=g(f(t),{separator:t.getAttribute("data-separator"),verticalSeparator:t.getAttribute("data-separator-vertical"),notesSeparator:t.getAttribute("data-separator-notes"),attributes:E(t)}):t.innerHTML=p(f(t))}),Promise.all(e).then(a)})}function y(a){return new Promise(function(e,t){var r=new XMLHttpRequest,i=a.getAttribute("data-markdown");datacharset=a.getAttribute("data-charset"),datacharset!=null&&datacharset!=""&&r.overrideMimeType("text/html; charset="+datacharset),r.onreadystatechange=function(n,s){s.readyState===4&&(s.status>=200&&s.status<300||s.status===0?e(s,i):t(s,i))}.bind(this,a,r),r.open("GET",i,!0);try{r.send()}catch(n){alert("Failed to get the Markdown file "+i+". Make sure that the presentation and the file are served by a HTTP server and the file can be found there. "+n),e(r,i)}})}function A(a,e,t){var r=new RegExp(t,"mg"),i=new RegExp('([^"= ]+?)="([^"=]+?)"',"mg"),n=a.nodeValue;if(matches=r.exec(n)){var s=matches[1];for(n=n.substring(0,matches.index)+n.substring(r.lastIndex),a.nodeValue=n;matchesClass=i.exec(s);)e.setAttribute(matchesClass[1],matchesClass[2]);return!0}return!1}function S(a,e,t,r,i){if(e!=null&&e.childNodes!=null&&e.childNodes.length>0){previousParentElement=e;for(var n=0;n<e.childNodes.length;n++){if(childElement=e.childNodes[n],n>0)for(j=n-1;j>=0;){if(aPreviousChildElement=e.childNodes[j],typeof aPreviousChildElement.setAttribute=="function"&&aPreviousChildElement.tagName!="BR"){previousParentElement=aPreviousChildElement;break}j=j-1}parentSection=a,childElement.nodeName=="section"&&(parentSection=childElement,previousParentElement=childElement),(typeof childElement.setAttribute=="function"||childElement.nodeType==Node.COMMENT_NODE)&&S(parentSection,childElement,previousParentElement,r,i)}}e.nodeType==Node.COMMENT_NODE&&A(e,t,r)==!1&&A(e,a,i)}function T(){var a=document.querySelectorAll("[data-markdown]:not([data-markdown-parsed])");return[].slice.call(a).forEach(function(e){e.setAttribute("data-markdown-parsed",!0);var t=e.querySelector("aside.notes"),r=f(e);e.innerHTML=l(r),S(e,e,null,e.getAttribute("data-element-attributes")||e.parentNode.getAttribute("data-element-attributes")||x,e.getAttribute("data-attributes")||e.parentNode.getAttribute("data-attributes")||P),t&&e.appendChild(t)}),Promise.resolve()}var R={init:function(a){if(typeof l=="undefined")throw"The reveal.js Markdown plugin requires marked to be loaded";typeof hljs!="undefined"&&l.setOptions({highlight:function(t,r){return hljs.highlightAuto(t,[r]).value}});var e=Reveal.getConfig().markdown;return e&&l.setOptions(e),w().then(T)},processSlides:w,convertSlides:T,slidify:g};return Reveal.registerPlugin("markdown",R),R});
