From b92d16f48df6e6e16c0cd5d232a3e787e59af8f9 Mon Sep 17 00:00:00 2001 From: Hakim El Hattab Date: Thu, 23 Apr 2020 10:54:48 +0200 Subject: [PATCH] make plugins work with multiple presentations on same page --- dist/plugin/highlight.js | 2 +- dist/plugin/markdown.js | 4 +- dist/plugin/math.js | 2 +- dist/plugin/search.js | 4 +- examples/multiple-presentations.html | 36 +- plugin/highlight/highlight.js | 18 +- plugin/markdown/markdown.js | 756 ++++++++++++++------------- plugin/math/math.js | 49 +- plugin/search/search.js | 316 +++++------ 9 files changed, 626 insertions(+), 561 deletions(-) diff --git a/dist/plugin/highlight.js b/dist/plugin/highlight.js index 56bf34e..96af7dc 100644 --- a/dist/plugin/highlight.js +++ b/dist/plugin/highlight.js @@ -3,4 +3,4 @@ /*! * reveal.js plugin that adds syntax highlight support. */ -var t={id:"highlight",HIGHLIGHT_STEP_DELIMITER:"|",HIGHLIGHT_LINE_DELIMITER:",",HIGHLIGHT_LINE_RANGE_DELIMITER:"-",init:function(e){var r=e.getConfig().highlight||{};r.highlightOnLoad="boolean"!=typeof r.highlightOnLoad||r.highlightOnLoad,r.escapeHTML="boolean"!=typeof r.escapeHTML||r.escapeHTML,[].slice.call(document.querySelectorAll(".reveal pre code")).forEach((function(e){e.hasAttribute("data-trim")&&"function"==typeof e.innerHTML.trim&&(e.innerHTML=function(e){function t(e){return e.replace(/^[\s\uFEFF\xA0]+/g,"")}return function(e){var r=function(e){for(var t=e.split("\n"),r=0;r=0&&""===t[r].trim();r--)t.splice(r,1);return t.join("\n")}(e.innerHTML).split("\n"),a=r.reduce((function(e,r){return r.length>0&&t(r).length>0&&e>r.length-t(r).length?r.length-t(r).length:e}),Number.POSITIVE_INFINITY);return r.map((function(e,t){return e.slice(a)})).join("\n")}(e)}(e)),r.escapeHTML&&!e.hasAttribute("data-noescape")&&(e.innerHTML=e.innerHTML.replace(//g,">")),e.addEventListener("focusout",(function(e){hljs.highlightBlock(e.currentTarget)}),!1),r.highlightOnLoad&&t.highlightBlock(e)})),e.on("pdf-ready",(function(){[].slice.call(document.querySelectorAll(".reveal pre code[data-line-numbers].current-fragment")).forEach((function(e){t.scrollHighlightedLineIntoView(e,{},!0)}))}))},highlightBlock:function(e){if(hljs.highlightBlock(e),0!==e.innerHTML.trim().length&&e.hasAttribute("data-line-numbers")){hljs.lineNumbersBlock(e,{singleLine:!0});var r={currentBlock:e},a=t.deserializeHighlightSteps(e.getAttribute("data-line-numbers"));if(a.length>1){var i=parseInt(e.getAttribute("data-fragment-index"),10);("number"!=typeof i||isNaN(i))&&(i=null),a.slice(1).forEach((function(a){var n=e.cloneNode(!0);n.setAttribute("data-line-numbers",t.serializeHighlightSteps([a])),n.classList.add("fragment"),e.parentNode.appendChild(n),t.highlightLines(n),"number"==typeof i?(n.setAttribute("data-fragment-index",i),i+=1):n.removeAttribute("data-fragment-index"),n.addEventListener("visible",t.scrollHighlightedLineIntoView.bind(t,n,r)),n.addEventListener("hidden",t.scrollHighlightedLineIntoView.bind(t,n.previousSibling,r))})),e.removeAttribute("data-fragment-index"),e.setAttribute("data-line-numbers",t.serializeHighlightSteps([a[0]]))}var n="function"==typeof e.closest?e.closest("section:not(.stack)"):null;if(n){n.addEventListener("visible",(function a(){t.scrollHighlightedLineIntoView(e,r,!0),n.removeEventListener("visible",a)}))}t.highlightLines(e)}},scrollHighlightedLineIntoView:function(e,r,a){cancelAnimationFrame(r.animationFrameID),r.currentBlock&&(e.scrollTop=r.currentBlock.scrollTop),r.currentBlock=e;var i=this.getHighlightedLineBounds(e),n=e.offsetHeight,o=getComputedStyle(e);n-=parseInt(o.paddingTop)+parseInt(o.paddingBottom);var s=e.scrollTop,l=i.top+(Math.min(i.bottom-i.top,n)-n)/2,c=e.querySelector(".hljs-ln");if(c&&(l+=c.offsetTop-parseInt(o.paddingTop)),l=Math.max(Math.min(l,e.scrollHeight-n),0),!0===a||s===l)e.scrollTop=l;else{if(e.scrollHeight<=n)return;var _=0;!function a(){_=Math.min(_+.02,1),e.scrollTop=s+(l-s)*t.easeInOutQuart(_),_<1&&(r.animationFrameID=requestAnimationFrame(a))}()}},easeInOutQuart:function(e){return e<.5?8*e*e*e*e:1-8*--e*e*e*e},getHighlightedLineBounds:function(e){var t=e.querySelectorAll(".highlight-line");if(0===t.length)return{top:0,bottom:0};var r=t[0],a=t[t.length-1];return{top:r.offsetTop,bottom:a.offsetTop+a.offsetHeight}},highlightLines:function(e,r){var a=t.deserializeHighlightSteps(r||e.getAttribute("data-line-numbers"));a.length&&a[0].forEach((function(t){var r=[];"number"==typeof t.end?r=[].slice.call(e.querySelectorAll("table tr:nth-child(n+"+t.start+"):nth-child(-n+"+t.end+")")):"number"==typeof t.start&&(r=[].slice.call(e.querySelectorAll("table tr:nth-child("+t.start+")"))),r.length&&(r.forEach((function(e){e.classList.add("highlight-line")})),e.classList.add("has-highlights"))}))},deserializeHighlightSteps:function(e){return(e=(e=e.replace(/\s/g,"")).split(t.HIGHLIGHT_STEP_DELIMITER)).map((function(e){return e.split(t.HIGHLIGHT_LINE_DELIMITER).map((function(e){if(/^[\d-]+$/.test(e)){e=e.split(t.HIGHLIGHT_LINE_RANGE_DELIMITER);var r=parseInt(e[0],10),a=parseInt(e[1],10);return isNaN(a)?{start:r}:{start:r,end:a}}return{}}))}))},serializeHighlightSteps:function(e){return e.map((function(e){return e.map((function(e){return"number"==typeof e.end?e.start+t.HIGHLIGHT_LINE_RANGE_DELIMITER+e.end:"number"==typeof e.start?e.start:""})).join(t.HIGHLIGHT_LINE_DELIMITER)})).join(t.HIGHLIGHT_STEP_DELIMITER)}};return function(){return t}})); +var t={id:"highlight",HIGHLIGHT_STEP_DELIMITER:"|",HIGHLIGHT_LINE_DELIMITER:",",HIGHLIGHT_LINE_RANGE_DELIMITER:"-",init:function(e){var r=e.getConfig().highlight||{};r.highlightOnLoad="boolean"!=typeof r.highlightOnLoad||r.highlightOnLoad,r.escapeHTML="boolean"!=typeof r.escapeHTML||r.escapeHTML,[].slice.call(e.getRevealElement().querySelectorAll("pre code")).forEach((function(e){e.hasAttribute("data-trim")&&"function"==typeof e.innerHTML.trim&&(e.innerHTML=function(e){function t(e){return e.replace(/^[\s\uFEFF\xA0]+/g,"")}return function(e){var r=function(e){for(var t=e.split("\n"),r=0;r=0&&""===t[r].trim();r--)t.splice(r,1);return t.join("\n")}(e.innerHTML).split("\n"),a=r.reduce((function(e,r){return r.length>0&&t(r).length>0&&e>r.length-t(r).length?r.length-t(r).length:e}),Number.POSITIVE_INFINITY);return r.map((function(e,t){return e.slice(a)})).join("\n")}(e)}(e)),r.escapeHTML&&!e.hasAttribute("data-noescape")&&(e.innerHTML=e.innerHTML.replace(//g,">")),e.addEventListener("focusout",(function(e){hljs.highlightBlock(e.currentTarget)}),!1),r.highlightOnLoad&&t.highlightBlock(e)})),e.on("pdf-ready",(function(){[].slice.call(e.getRevealElement().querySelectorAll("pre code[data-line-numbers].current-fragment")).forEach((function(e){t.scrollHighlightedLineIntoView(e,{},!0)}))}))},highlightBlock:function(e){if(hljs.highlightBlock(e),0!==e.innerHTML.trim().length&&e.hasAttribute("data-line-numbers")){hljs.lineNumbersBlock(e,{singleLine:!0});var r={currentBlock:e},a=t.deserializeHighlightSteps(e.getAttribute("data-line-numbers"));if(a.length>1){var i=parseInt(e.getAttribute("data-fragment-index"),10);("number"!=typeof i||isNaN(i))&&(i=null),a.slice(1).forEach((function(a){var n=e.cloneNode(!0);n.setAttribute("data-line-numbers",t.serializeHighlightSteps([a])),n.classList.add("fragment"),e.parentNode.appendChild(n),t.highlightLines(n),"number"==typeof i?(n.setAttribute("data-fragment-index",i),i+=1):n.removeAttribute("data-fragment-index"),n.addEventListener("visible",t.scrollHighlightedLineIntoView.bind(t,n,r)),n.addEventListener("hidden",t.scrollHighlightedLineIntoView.bind(t,n.previousSibling,r))})),e.removeAttribute("data-fragment-index"),e.setAttribute("data-line-numbers",t.serializeHighlightSteps([a[0]]))}var n="function"==typeof e.closest?e.closest("section:not(.stack)"):null;if(n){n.addEventListener("visible",(function a(){t.scrollHighlightedLineIntoView(e,r,!0),n.removeEventListener("visible",a)}))}t.highlightLines(e)}},scrollHighlightedLineIntoView:function(e,r,a){cancelAnimationFrame(r.animationFrameID),r.currentBlock&&(e.scrollTop=r.currentBlock.scrollTop),r.currentBlock=e;var i=this.getHighlightedLineBounds(e),n=e.offsetHeight,o=getComputedStyle(e);n-=parseInt(o.paddingTop)+parseInt(o.paddingBottom);var s=e.scrollTop,l=i.top+(Math.min(i.bottom-i.top,n)-n)/2,c=e.querySelector(".hljs-ln");if(c&&(l+=c.offsetTop-parseInt(o.paddingTop)),l=Math.max(Math.min(l,e.scrollHeight-n),0),!0===a||s===l)e.scrollTop=l;else{if(e.scrollHeight<=n)return;var _=0;!function a(){_=Math.min(_+.02,1),e.scrollTop=s+(l-s)*t.easeInOutQuart(_),_<1&&(r.animationFrameID=requestAnimationFrame(a))}()}},easeInOutQuart:function(e){return e<.5?8*e*e*e*e:1-8*--e*e*e*e},getHighlightedLineBounds:function(e){var t=e.querySelectorAll(".highlight-line");if(0===t.length)return{top:0,bottom:0};var r=t[0],a=t[t.length-1];return{top:r.offsetTop,bottom:a.offsetTop+a.offsetHeight}},highlightLines:function(e,r){var a=t.deserializeHighlightSteps(r||e.getAttribute("data-line-numbers"));a.length&&a[0].forEach((function(t){var r=[];"number"==typeof t.end?r=[].slice.call(e.querySelectorAll("table tr:nth-child(n+"+t.start+"):nth-child(-n+"+t.end+")")):"number"==typeof t.start&&(r=[].slice.call(e.querySelectorAll("table tr:nth-child("+t.start+")"))),r.length&&(r.forEach((function(e){e.classList.add("highlight-line")})),e.classList.add("has-highlights"))}))},deserializeHighlightSteps:function(e){return(e=(e=e.replace(/\s/g,"")).split(t.HIGHLIGHT_STEP_DELIMITER)).map((function(e){return e.split(t.HIGHLIGHT_LINE_DELIMITER).map((function(e){if(/^[\d-]+$/.test(e)){e=e.split(t.HIGHLIGHT_LINE_RANGE_DELIMITER);var r=parseInt(e[0],10),a=parseInt(e[1],10);return isNaN(a)?{start:r}:{start:r,end:a}}return{}}))}))},serializeHighlightSteps:function(e){return e.map((function(e){return e.map((function(e){return"number"==typeof e.end?e.start+t.HIGHLIGHT_LINE_RANGE_DELIMITER+e.end:"number"==typeof e.start?e.start:""})).join(t.HIGHLIGHT_LINE_DELIMITER)})).join(t.HIGHLIGHT_STEP_DELIMITER)}};return function(){return t}})); diff --git a/dist/plugin/markdown.js b/dist/plugin/markdown.js index ae803ba..2060705 100644 --- a/dist/plugin/markdown.js +++ b/dist/plugin/markdown.js @@ -1,6 +1,6 @@ -!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):(e=e||self).RevealMarkdown=t()}(this,(function(){"use strict";function e(t){return(e="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e})(t)}function t(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function n(e,t){for(var n=0;n"']/),a=/[&<>"']/g,l=/[<>"']|&(?!#?\w+;)/,o=/[<>"']|&(?!#?\w+;)/g,c={"&":"&","<":"<",">":">",'"':""","'":"'"},u=function(e){return c[e]};var h=/&(#(?:\d+)|(?:#x[0-9A-Fa-f]+)|(?:\w+));?/gi;function p(e){return e.replace(h,(function(e,t){return"colon"===(t=t.toLowerCase())?":":"#"===t.charAt(0)?"x"===t.charAt(1)?String.fromCharCode(parseInt(t.substring(2),16)):String.fromCharCode(+t.substring(1)):""}))}var g=/(^|[^\[])\^/g;var f=/[^\w:]/g,d=/^$|^[a-z][a-z0-9+.-]*:|^[?#]/i;var b={},k=/^[^:]+:\/*[^/]*$/,m=/^([^:]+:)[\s\S]*$/,x=/^([^:]+:\/*[^/]*)[\s\S]*$/;function y(e,t){b[" "+e]||(k.test(e)?b[" "+e]=e+"/":b[" "+e]=v(e,"/",!0));var n=-1===(e=b[" "+e]).indexOf(":");return"//"===t.substring(0,2)?n?t:e.replace(m,"$1")+t:"/"===t.charAt(0)?n?t:e.replace(x,"$1")+t:e+t}function v(e,t,n){var r=e.length;if(0===r)return"";for(var s=0;s=0&&"\\"===n[s];)r=!r;return r?"|":" |"})).split(/ \|/),r=0;if(n.length>t)n.splice(t);else for(;n.length ?(paragraph|[^\n]*)(?:\n|$))+/,list:/^( {0,3})(bull) [\s\S]+?(?:hr|def|\n{2,}(?! )(?!\1bull )\n*|\s*$)/,html:"^ {0,3}(?:<(script|pre|style)[\\s>][\\s\\S]*?(?:[^\\n]*\\n+|$)|comment[^\\n]*(\\n+|$)|<\\?[\\s\\S]*?\\?>\\n*|\\n*|\\n*|)[\\s\\S]*?(?:\\n{2,}|$)|<(?!script|pre|style)([a-z][\\w-]*)(?:attribute)*? */?>(?=[ \\t]*(?:\\n|$))[\\s\\S]*?(?:\\n{2,}|$)|(?=[ \\t]*(?:\\n|$))[\\s\\S]*?(?:\\n{2,}|$))",def:/^ {0,3}\[(label)\]: *\n? *]+)>?(?:(?: +\n? *| *\n *)(title))? *(?:\n+|$)/,nptable:E,table:E,lheading:/^([^\n]+)\n {0,3}(=+|-+) *(?:\n+|$)/,_paragraph:/^([^\n]+(?:\n(?!hr|heading|lheading|blockquote|fences|list|html)[^\n]+)*)/,text:/^[^\n]+/,_label:/(?!\s*\])(?:\\[\[\]]|[^\[\]])+/,_title:/(?:"(?:\\"?|[^"\\])*"|'[^'\n]*(?:\n[^'\n]+)*\n?'|\([^()]*\))/};C.def=L(C.def).replace("label",C._label).replace("title",C._title).getRegex(),C.bullet=/(?:[*+-]|\d{1,9}\.)/,C.item=/^( *)(bull) ?[^\n]*(?:\n(?!\1bull ?)[^\n]*)*/,C.item=L(C.item,"gm").replace(/bull/g,C.bullet).getRegex(),C.list=L(C.list).replace(/bull/g,C.bullet).replace("hr","\\n+(?=\\1?(?:(?:- *){3,}|(?:_ *){3,}|(?:\\* *){3,})(?:\\n+|$))").replace("def","\\n+(?="+C.def.source+")").getRegex(),C._tag="address|article|aside|base|basefont|blockquote|body|caption|center|col|colgroup|dd|details|dialog|dir|div|dl|dt|fieldset|figcaption|figure|footer|form|frame|frameset|h[1-6]|head|header|hr|html|iframe|legend|li|link|main|menu|menuitem|meta|nav|noframes|ol|optgroup|option|p|param|section|source|summary|table|tbody|td|tfoot|th|thead|title|tr|track|ul",C._comment=//,C.html=L(C.html,"i").replace("comment",C._comment).replace("tag",C._tag).replace("attribute",/ +[a-zA-Z:_][\w.:-]*(?: *= *"[^"\n]*"| *= *'[^'\n]*'| *= *[^\s"'=<>`]+)?/).getRegex(),C.paragraph=L(C._paragraph).replace("hr",C.hr).replace("heading"," {0,3}#{1,6} ").replace("|lheading","").replace("blockquote"," {0,3}>").replace("fences"," {0,3}(?:`{3,}(?=[^`\\n]*\\n)|~{3,})[^\\n]*\\n").replace("list"," {0,3}(?:[*+-]|1[.)]) ").replace("html",")|<(?:script|pre|style|!--)").replace("tag",C._tag).getRegex(),C.blockquote=L(C.blockquote).replace("paragraph",C.paragraph).getRegex(),C.normal=q({},C),C.gfm=q({},C.normal,{nptable:"^ *([^|\\n ].*\\|.*)\\n *([-:]+ *\\|[-| :]*)(?:\\n((?:(?!\\n|hr|heading|blockquote|code|fences|list|html).*(?:\\n|$))*)\\n*|$)",table:"^ *\\|(.+)\\n *\\|?( *[-:]+[-| :]*)(?:\\n *((?:(?!\\n|hr|heading|blockquote|code|fences|list|html).*(?:\\n|$))*)\\n*|$)"}),C.gfm.nptable=L(C.gfm.nptable).replace("hr",C.hr).replace("heading"," {0,3}#{1,6} ").replace("blockquote"," {0,3}>").replace("code"," {4}[^\\n]").replace("fences"," {0,3}(?:`{3,}(?=[^`\\n]*\\n)|~{3,})[^\\n]*\\n").replace("list"," {0,3}(?:[*+-]|1[.)]) ").replace("html",")|<(?:script|pre|style|!--)").replace("tag",C._tag).getRegex(),C.gfm.table=L(C.gfm.table).replace("hr",C.hr).replace("heading"," {0,3}#{1,6} ").replace("blockquote"," {0,3}>").replace("code"," {4}[^\\n]").replace("fences"," {0,3}(?:`{3,}(?=[^`\\n]*\\n)|~{3,})[^\\n]*\\n").replace("list"," {0,3}(?:[*+-]|1[.)]) ").replace("html",")|<(?:script|pre|style|!--)").replace("tag",C._tag).getRegex(),C.pedantic=q({},C.normal,{html:L("^ *(?:comment *(?:\\n|\\s*$)|<(tag)[\\s\\S]+? *(?:\\n{2,}|\\s*$)|\\s]*)*?/?> *(?:\\n{2,}|\\s*$))").replace("comment",C._comment).replace(/tag/g,"(?!(?:a|em|strong|small|s|cite|q|dfn|abbr|data|time|code|var|samp|kbd|sub|sup|i|b|u|mark|ruby|rt|rp|bdi|bdo|span|br|wbr|ins|del|img)\\b)\\w+(?!:|[^\\w\\s@]*@)\\b").getRegex(),def:/^ *\[([^\]]+)\]: *]+)>?(?: +(["(][^\n]+[")]))? *(?:\n+|$)/,heading:/^ *(#{1,6}) *([^\n]+?) *(?:#+ *)?(?:\n+|$)/,fences:E,paragraph:L(C.normal._paragraph).replace("hr",C.hr).replace("heading"," *#{1,6} *[^\n]").replace("lheading",C.lheading).replace("blockquote"," {0,3}>").replace("|fences","").replace("|list","").replace("|html","").getRegex()});var I={escape:/^\\([!"#$%&'()*+,\-./:;<=>?@\[\]\\^_`{|}~])/,autolink:/^<(scheme:[^\s\x00-\x1f<>]*|email)>/,url:E,tag:"^comment|^|^<[a-zA-Z][\\w-]*(?:attribute)*?\\s*/?>|^<\\?[\\s\\S]*?\\?>|^|^",link:/^!?\[(label)\]\(\s*(href)(?:\s+(title))?\s*\)/,reflink:/^!?\[(label)\]\[(?!\s*\])((?:\\[\[\]]?|[^\[\]\\])+)\]/,nolink:/^!?\[(?!\s*\])((?:\[[^\[\]]*\]|\\[\[\]]|[^\[\]])*)\](?:\[\])?/,strong:/^__([^\s_])__(?!_)|^\*\*([^\s*])\*\*(?!\*)|^__([^\s][\s\S]*?[^\s])__(?!_)|^\*\*([^\s][\s\S]*?[^\s])\*\*(?!\*)/,em:/^_([^\s_])_(?!_)|^_([^\s_<][\s\S]*?[^\s_])_(?!_|[^\spunctuation])|^_([^\s_<][\s\S]*?[^\s])_(?!_|[^\spunctuation])|^\*([^\s*<\[])\*(?!\*)|^\*([^\s<"][\s\S]*?[^\s\[\*])\*(?![\]`punctuation])|^\*([^\s*"<\[][\s\S]*[^\s])\*(?!\*)/,code:/^(`+)([^`]|[^`][\s\S]*?[^`])\1(?!`)/,br:/^( {2,}|\\)\n(?!\s*$)/,del:E,text:/^(`+|[^`])(?:[\s\S]*?(?:(?=[\\?@\\[^_{|}~"};I.em=L(I.em).replace(/punctuation/g,I._punctuation).getRegex(),I._escapes=/\\([!"#$%&'()*+,\-./:;<=>?@\[\]\\^_`{|}~])/g,I._scheme=/[a-zA-Z][a-zA-Z0-9+.-]{1,31}/,I._email=/[a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+(@)[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)+(?![-_])/,I.autolink=L(I.autolink).replace("scheme",I._scheme).replace("email",I._email).getRegex(),I._attribute=/\s+[a-zA-Z:_][\w.:-]*(?:\s*=\s*"[^"]*"|\s*=\s*'[^']*'|\s*=\s*[^\s"'=<>`]+)?/,I.tag=L(I.tag).replace("comment",C._comment).replace("attribute",I._attribute).getRegex(),I._label=/(?:\[[^\[\]]*\]|\\.|`[^`]*`|[^\[\]\\`])*?/,I._href=/<(?:\\[<>]?|[^\s<>\\])*>|[^\s\x00-\x1f]*/,I._title=/"(?:\\"?|[^"\\])*"|'(?:\\'?|[^'\\])*'|\((?:\\\)?|[^)\\])*\)/,I.link=L(I.link).replace("label",I._label).replace("href",I._href).replace("title",I._title).getRegex(),I.reflink=L(I.reflink).replace("label",I._label).getRegex(),I.normal=q({},I),I.pedantic=q({},I.normal,{strong:/^__(?=\S)([\s\S]*?\S)__(?!_)|^\*\*(?=\S)([\s\S]*?\S)\*\*(?!\*)/,em:/^_(?=\S)([\s\S]*?\S)_(?!_)|^\*(?=\S)([\s\S]*?\S)\*(?!\*)/,link:L(/^!?\[(label)\]\((.*?)\)/).replace("label",I._label).getRegex(),reflink:L(/^!?\[(label)\]\s*\[([^\]]*)\]/).replace("label",I._label).getRegex()}),I.gfm=q({},I.normal,{escape:L(I.escape).replace("])","~|])").getRegex(),_extended_email:/[A-Za-z0-9._+-]+(@)[a-zA-Z0-9-_]+(?:\.[a-zA-Z0-9-_]*[a-zA-Z0-9])+(?![-_])/,url:/^((?:ftp|https?):\/\/|www\.)(?:[a-zA-Z0-9\-]+\.?)+[^\s<]*|^email/,_backpedal:/(?:[^?!.,:;*_~()&]+|\([^)]*\)|&(?![a-zA-Z0-9]+;$)|[?!.,:;*_~)]+(?!$))+/,del:/^~+(?=\S)([\s\S]*?\S)~+/,text:/^(`+|[^`])(?:[\s\S]*?(?:(?=[\\2&&void 0!==arguments[2])||arguments[2];for(e=e.replace(/^ +$/gm,"");e;)if((s=this.rules.block.newline.exec(e))&&(e=e.substring(s[0].length),m=s[0],s[0].length>1&&t.push({type:"space",raw:m})),s=this.rules.block.code.exec(e))b=t[t.length-1],e=e.substring(s[0].length),m=s[0],b&&"paragraph"===b.type?(b.text+="\n"+s[0].trimRight(),b.raw+="\n"+m):(s=s[0].replace(/^ {4}/gm,""),t.push({type:"code",raw:m,codeBlockStyle:"indented",text:this.options.pedantic?s:M(s,"\n")}));else if(s=this.rules.block.fences.exec(e))e=e.substring(s[0].length),m=s[0],t.push({type:"code",raw:m,lang:s[2]?s[2].trim():s[2],text:s[3]||""});else if(s=this.rules.block.heading.exec(e))e=e.substring(s[0].length),m=s[0],t.push({type:"heading",raw:m,depth:s[1].length,text:s[2]});else if((s=this.rules.block.nptable.exec(e))&&(l={type:"table",header:D(s[1].replace(/^ *| *\| *$/g,"")),align:s[2].replace(/^ *|\| *$/g,"").split(/ *\| */),cells:s[3]?s[3].replace(/\n$/,"").split("\n"):[]}).header.length===l.align.length){for(e=e.substring(s[0].length),m=s[0],l.raw=m,p=l.align.length,u=0;u ?/gm,""),t.push({type:"blockquote",raw:m,tokens:this.blockTokens(s,[],x)});else if(s=this.rules.block.list.exec(e))for(e=e.substring(s[0].length),o={type:"list",raw:m=s[0],ordered:g=(i=s[2]).length>1,start:g?+i:"",loose:!1,items:[]},t.push(o),n=!1,p=(s=s[0].match(this.rules.block.item)).length,u=0;u1?1===a.length:a.length>1||this.options.smartLists&&a!==i)&&(e=(k=s.slice(u+1).join("\n"))+e,o.raw=o.raw.substring(o.raw.length-k.length),u=p-1)),r=n||/\n\n(?!\s*$)/.test(l),u!==p-1&&(n="\n"===l.charAt(l.length-1),r||(r=n)),r&&(o.loose=!0),d=void 0,(f=/^\[[ xX]\] /.test(l))&&(d=" "!==l[1],l=l.replace(/^\[[ xX]\] +/,"")),o.items.push({raw:m,task:f,checked:d,loose:r,tokens:this.blockTokens(l,[],!1)});else if(s=this.rules.block.html.exec(e))e=e.substring(s[0].length),m=s[0],t.push({type:this.options.sanitize?"paragraph":"html",raw:m,pre:!this.options.sanitizer&&("pre"===s[1]||"script"===s[1]||"style"===s[1]),text:this.options.sanitize?this.options.sanitizer?this.options.sanitizer(s[0]):j(s[0]):s[0]});else if(x&&(s=this.rules.block.def.exec(e)))e=e.substring(s[0].length),s[3]&&(s[3]=s[3].substring(1,s[3].length-1)),h=s[1].toLowerCase().replace(/\s+/g," "),this.tokens.links[h]||(this.tokens.links[h]={href:s[2],title:s[3]});else if((s=this.rules.block.table.exec(e))&&(l={type:"table",header:D(s[1].replace(/^ *| *\| *$/g,"")),align:s[2].replace(/^ *|\| *$/g,"").split(/ *\| */),cells:s[3]?s[3].replace(/\n$/,"").split("\n"):[]}).header.length===l.align.length){for(e=e.substring(s[0].length),l.raw=s[0],p=l.align.length,u=0;u/i.test(l[0])&&(this.inLink=!1),!this.inRawBlock&&/^<(pre|code|kbd|script)(\s|>)/i.test(l[0])?this.inRawBlock=!0:this.inRawBlock&&/^<\/(pre|code|kbd|script)(\s|>)/i.test(l[0])&&(this.inRawBlock=!1),e=e.substring(l[0].length),h=l[0],r=this.options.sanitize?this.options.sanitizer?this.options.sanitizer(l[0]):j(l[0]):l[0],t.push({type:this.options.sanitize?"text":"html",raw:h,text:r}),p+=r;else if(l=this.rules.inline.link.exec(e))(c=H(l[2],"()"))>-1&&(u=(0===l[0].indexOf("!")?5:4)+l[1].length+c,l[2]=l[2].substring(0,c),l[0]=l[0].substring(0,u).trim(),l[3]=""),e=e.substring(l[0].length),h=l[0],this.inLink=!0,i=l[2],this.options.pedantic?(n=/^([^'"]*[^\s])\s+(['"])(.*)\2/.exec(i))?(i=n[1],a=n[3]):a="":a=l[3]?l[3].slice(1,-1):"",i=i.trim().replace(/^<([\s\S]*)>$/,"$1"),p+=this.outputLink(l,{href:this.escapes(i),title:this.escapes(a)},t,h),this.inLink=!1;else if((l=this.rules.inline.reflink.exec(e))||(l=this.rules.inline.nolink.exec(e))){if(e=e.substring(l[0].length),h=l[0],n=(l[2]||l[1]).replace(/\s+/g," "),!(n=this.tokens.links[n.toLowerCase()])||!n.href){p+=r=l[0].charAt(0),t.push({type:"text",raw:r,text:r}),e=l[0].substring(1)+e;continue}this.inLink=!0,p+=this.outputLink(l,n,t,h),this.inLink=!1}else if(l=this.rules.inline.strong.exec(e))e=e.substring(l[0].length),h=l[0],s=t?[]:null,r=this.inlineTokens(l[4]||l[3]||l[2]||l[1],s),t.push({type:"strong",raw:h,text:r,tokens:s}),p+=r;else if(l=this.rules.inline.em.exec(e))e=e.substring(l[0].length),h=l[0],s=t?[]:null,r=this.inlineTokens(l[6]||l[5]||l[4]||l[3]||l[2]||l[1],s),t.push({type:"em",raw:h,text:r,tokens:s}),p+=r;else if(l=this.rules.inline.code.exec(e))e=e.substring(l[0].length),h=l[0],r=j(l[2].trim(),!0),t.push({type:"codespan",raw:h,text:r}),p+=r;else if(l=this.rules.inline.br.exec(e))e=e.substring(l[0].length),h=l[0],t.push({type:"br",raw:h}),p+="\n";else if(l=this.rules.inline.del.exec(e))e=e.substring(l[0].length),h=l[0],s=t?[]:null,r=this.inlineTokens(l[1],s),t.push({type:"del",raw:h,text:r,tokens:s}),p+=r;else if(l=this.rules.inline.autolink.exec(e))e=e.substring(l[0].length),h=l[0],i="@"===l[2]?"mailto:"+(r=j(this.options.mangle?this.mangle(l[1]):l[1])):r=j(l[1]),t.push({type:"link",raw:h,text:r,href:i,tokens:[{type:"text",raw:r,text:r}]}),p+=r;else if(this.inLink||!(l=this.rules.inline.url.exec(e))){if(l=this.rules.inline.text.exec(e))e=e.substring(l[0].length),h=l[0],r=this.inRawBlock?this.options.sanitize?this.options.sanitizer?this.options.sanitizer(l[0]):j(l[0]):l[0]:j(this.options.smartypants?this.smartypants(l[0]):l[0]),t.push({type:"text",raw:h,text:r}),p+=r;else if(e){var g="Infinite loop on byte: "+e.charCodeAt(0);if(!this.options.silent)throw new Error(g);console.error(g)}}else{if("@"===l[2])i="mailto:"+(r=j(this.options.mangle?this.mangle(l[0]):l[0]));else{do{o=l[0],l[0]=this.rules.inline._backpedal.exec(l[0])[0]}while(o!==l[0]);r=j(l[0]),i="www."===l[1]?"http://"+r:r}e=e.substring(l[0].length),h=l[0],t.push({type:"link",raw:h,text:r,href:i,tokens:[{type:"text",raw:r,text:r}]}),p+=r}return p}},{key:"escapes",value:function(e){return e?e.replace(N._escapes,"$1"):e}},{key:"outputLink",value:function(e,t,n,r){var s=t.href,i=t.title?j(t.title):null,a=n?[]:null;if("!"!==e[0].charAt(0)){var l=this.inlineTokens(e[1],a);return n.push({type:"link",raw:r,text:l,href:s,title:i,tokens:a}),l}var o=j(e[1]);return n.push({type:"image",raw:r,text:o,href:s,title:i}),o}},{key:"smartypants",value:function(e){return e.replace(/---/g,"—").replace(/--/g,"–").replace(/(^|[-\u2014/(\[{"\s])'/g,"$1‘").replace(/'/g,"’").replace(/(^|[-\u2014/(\[{\u2018\s])"/g,"$1“").replace(/"/g,"”").replace(/\.{3}/g,"…")}},{key:"mangle",value:function(e){var t,n,r="",s=e.length;for(t=0;t.5&&(n="x"+n.toString(16)),r+="&#"+n+";";return r}}],[{key:"lex",value:function(t,n){return new e(n).lex(t)}},{key:"rules",get:function(){return{block:P,inline:N}}}]),e}(),U=s.defaults,F=S,V=w,X=function(){function e(n){t(this,e),this.options=n||U}return r(e,[{key:"code",value:function(e,t,n){var r=(t||"").match(/\S*/)[0];if(this.options.highlight){var s=this.options.highlight(e,r);null!=s&&s!==e&&(n=!0,e=s)}return r?'
'+(n?e:V(e,!0))+"
\n":"
"+(n?e:V(e,!0))+"
"}},{key:"blockquote",value:function(e){return"
\n"+e+"
\n"}},{key:"html",value:function(e){return e}},{key:"heading",value:function(e,t,n,r){return this.options.headerIds?"'+e+"\n":""+e+"\n"}},{key:"hr",value:function(){return this.options.xhtml?"
\n":"
\n"}},{key:"list",value:function(e,t,n){var r=t?"ol":"ul";return"<"+r+(t&&1!==n?' start="'+n+'"':"")+">\n"+e+"\n"}},{key:"listitem",value:function(e){return"
  • "+e+"
  • \n"}},{key:"checkbox",value:function(e){return" "}},{key:"paragraph",value:function(e){return"

    "+e+"

    \n"}},{key:"table",value:function(e,t){return t&&(t=""+t+""),"\n\n"+e+"\n"+t+"
    \n"}},{key:"tablerow",value:function(e){return"\n"+e+"\n"}},{key:"tablecell",value:function(e,t){var n=t.header?"th":"td";return(t.align?"<"+n+' align="'+t.align+'">':"<"+n+">")+e+"\n"}},{key:"strong",value:function(e){return""+e+""}},{key:"em",value:function(e){return""+e+""}},{key:"codespan",value:function(e){return""+e+""}},{key:"br",value:function(){return this.options.xhtml?"
    ":"
    "}},{key:"del",value:function(e){return""+e+""}},{key:"link",value:function(e,t,n){if(null===(e=F(this.options.sanitize,this.options.baseUrl,e)))return n;var r='"}},{key:"image",value:function(e,t,n){if(null===(e=F(this.options.sanitize,this.options.baseUrl,e)))return n;var r=''+n+'":">"}},{key:"text",value:function(e){return e}}]),e}(),G=function(){function e(){t(this,e)}return r(e,[{key:"strong",value:function(e){return e}},{key:"em",value:function(e){return e}},{key:"codespan",value:function(e){return e}},{key:"del",value:function(e){return e}},{key:"html",value:function(e){return e}},{key:"text",value:function(e){return e}},{key:"link",value:function(e,t,n){return""+n}},{key:"image",value:function(e,t,n){return""+n}},{key:"br",value:function(){return""}}]),e}(),J=function(){function e(){t(this,e),this.seen={}}return r(e,[{key:"slug",value:function(e){var t=e.toLowerCase().trim().replace(/<[!\/a-z].*?>/gi,"").replace(/[\u2000-\u206F\u2E00-\u2E7F\\'!"#$%&()*+,./:;<=>?@[\]^`{|}~]/g,"").replace(/\s/g,"-");if(this.seen.hasOwnProperty(t)){var n=t;do{this.seen[n]++,t=n+"-"+this.seen[n]}while(this.seen.hasOwnProperty(t))}return this.seen[t]=0,t}}]),e}(),K=s.defaults,Q=_,W=function(){function e(n){t(this,e),this.options=n||K,this.options.renderer=this.options.renderer||new X,this.renderer=this.options.renderer,this.renderer.options=this.options,this.textRenderer=new G,this.slugger=new J}return r(e,[{key:"parse",value:function(e){var t,n,r,s,i,a,l,o,c,u,h,p,g,f,d,b,k,m,x=!(arguments.length>1&&void 0!==arguments[1])||arguments[1],y="",v=e.length;for(t=0;t0&&"text"===d.tokens[0].tokens[0].type&&(d.tokens[0].tokens[0].text=m+" "+d.tokens[0].tokens[0].text)):d.tokens.unshift({type:"text",text:m}):f+=m),f+=this.parse(d.tokens,g),c+=this.renderer.listitem(f,k,b);y+=this.renderer.list(c,h,p);continue;case"html":y+=this.renderer.html(u.text);continue;case"paragraph":y+=this.renderer.paragraph(this.parseInline(u.tokens));continue;case"text":for(c=u.tokens?this.parseInline(u.tokens):u.text;t+1An error occurred:

    "+te(e.message+"",!0)+"
    ";throw e}}ie.options=ie.setOptions=function(e){return Y(ie.defaults,e),re(ie.defaults),ie},ie.getDefaults=ne,ie.defaults=se,ie.Parser=W,ie.parser=W.parse,ie.Renderer=X,ie.TextRenderer=G,ie.Lexer=B,ie.lexer=B.lex,ie.Slugger=J,ie.parse=ie;var ae=ie,le={id:"markdown",init:function(e){var t=e.getConfig().markdown;return t&&ae.setOptions(t),ge(e.getRevealElement()).then(de)},processSlides:ge,convertSlides:de,slidify:pe,marked:ae}; +!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):(e=e||self).RevealMarkdown=t()}(this,(function(){"use strict";function e(t){return(e="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e})(t)}function t(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function n(e,t){for(var n=0;n"']/),a=/[&<>"']/g,l=/[<>"']|&(?!#?\w+;)/,o=/[<>"']|&(?!#?\w+;)/g,c={"&":"&","<":"<",">":">",'"':""","'":"'"},u=function(e){return c[e]};var h=/&(#(?:\d+)|(?:#x[0-9A-Fa-f]+)|(?:\w+));?/gi;function p(e){return e.replace(h,(function(e,t){return"colon"===(t=t.toLowerCase())?":":"#"===t.charAt(0)?"x"===t.charAt(1)?String.fromCharCode(parseInt(t.substring(2),16)):String.fromCharCode(+t.substring(1)):""}))}var g=/(^|[^\[])\^/g;var f=/[^\w:]/g,d=/^$|^[a-z][a-z0-9+.-]*:|^[?#]/i;var b={},k=/^[^:]+:\/*[^/]*$/,m=/^([^:]+:)[\s\S]*$/,x=/^([^:]+:\/*[^/]*)[\s\S]*$/;function y(e,t){b[" "+e]||(k.test(e)?b[" "+e]=e+"/":b[" "+e]=v(e,"/",!0));var n=-1===(e=b[" "+e]).indexOf(":");return"//"===t.substring(0,2)?n?t:e.replace(m,"$1")+t:"/"===t.charAt(0)?n?t:e.replace(x,"$1")+t:e+t}function v(e,t,n){var r=e.length;if(0===r)return"";for(var s=0;s=0&&"\\"===n[s];)r=!r;return r?"|":" |"})).split(/ \|/),r=0;if(n.length>t)n.splice(t);else for(;n.length ?(paragraph|[^\n]*)(?:\n|$))+/,list:/^( {0,3})(bull) [\s\S]+?(?:hr|def|\n{2,}(?! )(?!\1bull )\n*|\s*$)/,html:"^ {0,3}(?:<(script|pre|style)[\\s>][\\s\\S]*?(?:[^\\n]*\\n+|$)|comment[^\\n]*(\\n+|$)|<\\?[\\s\\S]*?\\?>\\n*|\\n*|\\n*|)[\\s\\S]*?(?:\\n{2,}|$)|<(?!script|pre|style)([a-z][\\w-]*)(?:attribute)*? */?>(?=[ \\t]*(?:\\n|$))[\\s\\S]*?(?:\\n{2,}|$)|(?=[ \\t]*(?:\\n|$))[\\s\\S]*?(?:\\n{2,}|$))",def:/^ {0,3}\[(label)\]: *\n? *]+)>?(?:(?: +\n? *| *\n *)(title))? *(?:\n+|$)/,nptable:E,table:E,lheading:/^([^\n]+)\n {0,3}(=+|-+) *(?:\n+|$)/,_paragraph:/^([^\n]+(?:\n(?!hr|heading|lheading|blockquote|fences|list|html)[^\n]+)*)/,text:/^[^\n]+/,_label:/(?!\s*\])(?:\\[\[\]]|[^\[\]])+/,_title:/(?:"(?:\\"?|[^"\\])*"|'[^'\n]*(?:\n[^'\n]+)*\n?'|\([^()]*\))/};C.def=L(C.def).replace("label",C._label).replace("title",C._title).getRegex(),C.bullet=/(?:[*+-]|\d{1,9}\.)/,C.item=/^( *)(bull) ?[^\n]*(?:\n(?!\1bull ?)[^\n]*)*/,C.item=L(C.item,"gm").replace(/bull/g,C.bullet).getRegex(),C.list=L(C.list).replace(/bull/g,C.bullet).replace("hr","\\n+(?=\\1?(?:(?:- *){3,}|(?:_ *){3,}|(?:\\* *){3,})(?:\\n+|$))").replace("def","\\n+(?="+C.def.source+")").getRegex(),C._tag="address|article|aside|base|basefont|blockquote|body|caption|center|col|colgroup|dd|details|dialog|dir|div|dl|dt|fieldset|figcaption|figure|footer|form|frame|frameset|h[1-6]|head|header|hr|html|iframe|legend|li|link|main|menu|menuitem|meta|nav|noframes|ol|optgroup|option|p|param|section|source|summary|table|tbody|td|tfoot|th|thead|title|tr|track|ul",C._comment=//,C.html=L(C.html,"i").replace("comment",C._comment).replace("tag",C._tag).replace("attribute",/ +[a-zA-Z:_][\w.:-]*(?: *= *"[^"\n]*"| *= *'[^'\n]*'| *= *[^\s"'=<>`]+)?/).getRegex(),C.paragraph=L(C._paragraph).replace("hr",C.hr).replace("heading"," {0,3}#{1,6} ").replace("|lheading","").replace("blockquote"," {0,3}>").replace("fences"," {0,3}(?:`{3,}(?=[^`\\n]*\\n)|~{3,})[^\\n]*\\n").replace("list"," {0,3}(?:[*+-]|1[.)]) ").replace("html",")|<(?:script|pre|style|!--)").replace("tag",C._tag).getRegex(),C.blockquote=L(C.blockquote).replace("paragraph",C.paragraph).getRegex(),C.normal=q({},C),C.gfm=q({},C.normal,{nptable:"^ *([^|\\n ].*\\|.*)\\n *([-:]+ *\\|[-| :]*)(?:\\n((?:(?!\\n|hr|heading|blockquote|code|fences|list|html).*(?:\\n|$))*)\\n*|$)",table:"^ *\\|(.+)\\n *\\|?( *[-:]+[-| :]*)(?:\\n *((?:(?!\\n|hr|heading|blockquote|code|fences|list|html).*(?:\\n|$))*)\\n*|$)"}),C.gfm.nptable=L(C.gfm.nptable).replace("hr",C.hr).replace("heading"," {0,3}#{1,6} ").replace("blockquote"," {0,3}>").replace("code"," {4}[^\\n]").replace("fences"," {0,3}(?:`{3,}(?=[^`\\n]*\\n)|~{3,})[^\\n]*\\n").replace("list"," {0,3}(?:[*+-]|1[.)]) ").replace("html",")|<(?:script|pre|style|!--)").replace("tag",C._tag).getRegex(),C.gfm.table=L(C.gfm.table).replace("hr",C.hr).replace("heading"," {0,3}#{1,6} ").replace("blockquote"," {0,3}>").replace("code"," {4}[^\\n]").replace("fences"," {0,3}(?:`{3,}(?=[^`\\n]*\\n)|~{3,})[^\\n]*\\n").replace("list"," {0,3}(?:[*+-]|1[.)]) ").replace("html",")|<(?:script|pre|style|!--)").replace("tag",C._tag).getRegex(),C.pedantic=q({},C.normal,{html:L("^ *(?:comment *(?:\\n|\\s*$)|<(tag)[\\s\\S]+? *(?:\\n{2,}|\\s*$)|\\s]*)*?/?> *(?:\\n{2,}|\\s*$))").replace("comment",C._comment).replace(/tag/g,"(?!(?:a|em|strong|small|s|cite|q|dfn|abbr|data|time|code|var|samp|kbd|sub|sup|i|b|u|mark|ruby|rt|rp|bdi|bdo|span|br|wbr|ins|del|img)\\b)\\w+(?!:|[^\\w\\s@]*@)\\b").getRegex(),def:/^ *\[([^\]]+)\]: *]+)>?(?: +(["(][^\n]+[")]))? *(?:\n+|$)/,heading:/^ *(#{1,6}) *([^\n]+?) *(?:#+ *)?(?:\n+|$)/,fences:E,paragraph:L(C.normal._paragraph).replace("hr",C.hr).replace("heading"," *#{1,6} *[^\n]").replace("lheading",C.lheading).replace("blockquote"," {0,3}>").replace("|fences","").replace("|list","").replace("|html","").getRegex()});var I={escape:/^\\([!"#$%&'()*+,\-./:;<=>?@\[\]\\^_`{|}~])/,autolink:/^<(scheme:[^\s\x00-\x1f<>]*|email)>/,url:E,tag:"^comment|^|^<[a-zA-Z][\\w-]*(?:attribute)*?\\s*/?>|^<\\?[\\s\\S]*?\\?>|^|^",link:/^!?\[(label)\]\(\s*(href)(?:\s+(title))?\s*\)/,reflink:/^!?\[(label)\]\[(?!\s*\])((?:\\[\[\]]?|[^\[\]\\])+)\]/,nolink:/^!?\[(?!\s*\])((?:\[[^\[\]]*\]|\\[\[\]]|[^\[\]])*)\](?:\[\])?/,strong:/^__([^\s_])__(?!_)|^\*\*([^\s*])\*\*(?!\*)|^__([^\s][\s\S]*?[^\s])__(?!_)|^\*\*([^\s][\s\S]*?[^\s])\*\*(?!\*)/,em:/^_([^\s_])_(?!_)|^_([^\s_<][\s\S]*?[^\s_])_(?!_|[^\spunctuation])|^_([^\s_<][\s\S]*?[^\s])_(?!_|[^\spunctuation])|^\*([^\s*<\[])\*(?!\*)|^\*([^\s<"][\s\S]*?[^\s\[\*])\*(?![\]`punctuation])|^\*([^\s*"<\[][\s\S]*[^\s])\*(?!\*)/,code:/^(`+)([^`]|[^`][\s\S]*?[^`])\1(?!`)/,br:/^( {2,}|\\)\n(?!\s*$)/,del:E,text:/^(`+|[^`])(?:[\s\S]*?(?:(?=[\\?@\\[^_{|}~"};I.em=L(I.em).replace(/punctuation/g,I._punctuation).getRegex(),I._escapes=/\\([!"#$%&'()*+,\-./:;<=>?@\[\]\\^_`{|}~])/g,I._scheme=/[a-zA-Z][a-zA-Z0-9+.-]{1,31}/,I._email=/[a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+(@)[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)+(?![-_])/,I.autolink=L(I.autolink).replace("scheme",I._scheme).replace("email",I._email).getRegex(),I._attribute=/\s+[a-zA-Z:_][\w.:-]*(?:\s*=\s*"[^"]*"|\s*=\s*'[^']*'|\s*=\s*[^\s"'=<>`]+)?/,I.tag=L(I.tag).replace("comment",C._comment).replace("attribute",I._attribute).getRegex(),I._label=/(?:\[[^\[\]]*\]|\\.|`[^`]*`|[^\[\]\\`])*?/,I._href=/<(?:\\[<>]?|[^\s<>\\])*>|[^\s\x00-\x1f]*/,I._title=/"(?:\\"?|[^"\\])*"|'(?:\\'?|[^'\\])*'|\((?:\\\)?|[^)\\])*\)/,I.link=L(I.link).replace("label",I._label).replace("href",I._href).replace("title",I._title).getRegex(),I.reflink=L(I.reflink).replace("label",I._label).getRegex(),I.normal=q({},I),I.pedantic=q({},I.normal,{strong:/^__(?=\S)([\s\S]*?\S)__(?!_)|^\*\*(?=\S)([\s\S]*?\S)\*\*(?!\*)/,em:/^_(?=\S)([\s\S]*?\S)_(?!_)|^\*(?=\S)([\s\S]*?\S)\*(?!\*)/,link:L(/^!?\[(label)\]\((.*?)\)/).replace("label",I._label).getRegex(),reflink:L(/^!?\[(label)\]\s*\[([^\]]*)\]/).replace("label",I._label).getRegex()}),I.gfm=q({},I.normal,{escape:L(I.escape).replace("])","~|])").getRegex(),_extended_email:/[A-Za-z0-9._+-]+(@)[a-zA-Z0-9-_]+(?:\.[a-zA-Z0-9-_]*[a-zA-Z0-9])+(?![-_])/,url:/^((?:ftp|https?):\/\/|www\.)(?:[a-zA-Z0-9\-]+\.?)+[^\s<]*|^email/,_backpedal:/(?:[^?!.,:;*_~()&]+|\([^)]*\)|&(?![a-zA-Z0-9]+;$)|[?!.,:;*_~)]+(?!$))+/,del:/^~+(?=\S)([\s\S]*?\S)~+/,text:/^(`+|[^`])(?:[\s\S]*?(?:(?=[\\2&&void 0!==arguments[2])||arguments[2];for(e=e.replace(/^ +$/gm,"");e;)if((s=this.rules.block.newline.exec(e))&&(e=e.substring(s[0].length),m=s[0],s[0].length>1&&t.push({type:"space",raw:m})),s=this.rules.block.code.exec(e))b=t[t.length-1],e=e.substring(s[0].length),m=s[0],b&&"paragraph"===b.type?(b.text+="\n"+s[0].trimRight(),b.raw+="\n"+m):(s=s[0].replace(/^ {4}/gm,""),t.push({type:"code",raw:m,codeBlockStyle:"indented",text:this.options.pedantic?s:M(s,"\n")}));else if(s=this.rules.block.fences.exec(e))e=e.substring(s[0].length),m=s[0],t.push({type:"code",raw:m,lang:s[2]?s[2].trim():s[2],text:s[3]||""});else if(s=this.rules.block.heading.exec(e))e=e.substring(s[0].length),m=s[0],t.push({type:"heading",raw:m,depth:s[1].length,text:s[2]});else if((s=this.rules.block.nptable.exec(e))&&(l={type:"table",header:D(s[1].replace(/^ *| *\| *$/g,"")),align:s[2].replace(/^ *|\| *$/g,"").split(/ *\| */),cells:s[3]?s[3].replace(/\n$/,"").split("\n"):[]}).header.length===l.align.length){for(e=e.substring(s[0].length),m=s[0],l.raw=m,p=l.align.length,u=0;u ?/gm,""),t.push({type:"blockquote",raw:m,tokens:this.blockTokens(s,[],x)});else if(s=this.rules.block.list.exec(e))for(e=e.substring(s[0].length),o={type:"list",raw:m=s[0],ordered:g=(i=s[2]).length>1,start:g?+i:"",loose:!1,items:[]},t.push(o),n=!1,p=(s=s[0].match(this.rules.block.item)).length,u=0;u1?1===a.length:a.length>1||this.options.smartLists&&a!==i)&&(e=(k=s.slice(u+1).join("\n"))+e,o.raw=o.raw.substring(o.raw.length-k.length),u=p-1)),r=n||/\n\n(?!\s*$)/.test(l),u!==p-1&&(n="\n"===l.charAt(l.length-1),r||(r=n)),r&&(o.loose=!0),d=void 0,(f=/^\[[ xX]\] /.test(l))&&(d=" "!==l[1],l=l.replace(/^\[[ xX]\] +/,"")),o.items.push({raw:m,task:f,checked:d,loose:r,tokens:this.blockTokens(l,[],!1)});else if(s=this.rules.block.html.exec(e))e=e.substring(s[0].length),m=s[0],t.push({type:this.options.sanitize?"paragraph":"html",raw:m,pre:!this.options.sanitizer&&("pre"===s[1]||"script"===s[1]||"style"===s[1]),text:this.options.sanitize?this.options.sanitizer?this.options.sanitizer(s[0]):j(s[0]):s[0]});else if(x&&(s=this.rules.block.def.exec(e)))e=e.substring(s[0].length),s[3]&&(s[3]=s[3].substring(1,s[3].length-1)),h=s[1].toLowerCase().replace(/\s+/g," "),this.tokens.links[h]||(this.tokens.links[h]={href:s[2],title:s[3]});else if((s=this.rules.block.table.exec(e))&&(l={type:"table",header:D(s[1].replace(/^ *| *\| *$/g,"")),align:s[2].replace(/^ *|\| *$/g,"").split(/ *\| */),cells:s[3]?s[3].replace(/\n$/,"").split("\n"):[]}).header.length===l.align.length){for(e=e.substring(s[0].length),l.raw=s[0],p=l.align.length,u=0;u/i.test(l[0])&&(this.inLink=!1),!this.inRawBlock&&/^<(pre|code|kbd|script)(\s|>)/i.test(l[0])?this.inRawBlock=!0:this.inRawBlock&&/^<\/(pre|code|kbd|script)(\s|>)/i.test(l[0])&&(this.inRawBlock=!1),e=e.substring(l[0].length),h=l[0],r=this.options.sanitize?this.options.sanitizer?this.options.sanitizer(l[0]):j(l[0]):l[0],t.push({type:this.options.sanitize?"text":"html",raw:h,text:r}),p+=r;else if(l=this.rules.inline.link.exec(e))(c=H(l[2],"()"))>-1&&(u=(0===l[0].indexOf("!")?5:4)+l[1].length+c,l[2]=l[2].substring(0,c),l[0]=l[0].substring(0,u).trim(),l[3]=""),e=e.substring(l[0].length),h=l[0],this.inLink=!0,i=l[2],this.options.pedantic?(n=/^([^'"]*[^\s])\s+(['"])(.*)\2/.exec(i))?(i=n[1],a=n[3]):a="":a=l[3]?l[3].slice(1,-1):"",i=i.trim().replace(/^<([\s\S]*)>$/,"$1"),p+=this.outputLink(l,{href:this.escapes(i),title:this.escapes(a)},t,h),this.inLink=!1;else if((l=this.rules.inline.reflink.exec(e))||(l=this.rules.inline.nolink.exec(e))){if(e=e.substring(l[0].length),h=l[0],n=(l[2]||l[1]).replace(/\s+/g," "),!(n=this.tokens.links[n.toLowerCase()])||!n.href){p+=r=l[0].charAt(0),t.push({type:"text",raw:r,text:r}),e=l[0].substring(1)+e;continue}this.inLink=!0,p+=this.outputLink(l,n,t,h),this.inLink=!1}else if(l=this.rules.inline.strong.exec(e))e=e.substring(l[0].length),h=l[0],s=t?[]:null,r=this.inlineTokens(l[4]||l[3]||l[2]||l[1],s),t.push({type:"strong",raw:h,text:r,tokens:s}),p+=r;else if(l=this.rules.inline.em.exec(e))e=e.substring(l[0].length),h=l[0],s=t?[]:null,r=this.inlineTokens(l[6]||l[5]||l[4]||l[3]||l[2]||l[1],s),t.push({type:"em",raw:h,text:r,tokens:s}),p+=r;else if(l=this.rules.inline.code.exec(e))e=e.substring(l[0].length),h=l[0],r=j(l[2].trim(),!0),t.push({type:"codespan",raw:h,text:r}),p+=r;else if(l=this.rules.inline.br.exec(e))e=e.substring(l[0].length),h=l[0],t.push({type:"br",raw:h}),p+="\n";else if(l=this.rules.inline.del.exec(e))e=e.substring(l[0].length),h=l[0],s=t?[]:null,r=this.inlineTokens(l[1],s),t.push({type:"del",raw:h,text:r,tokens:s}),p+=r;else if(l=this.rules.inline.autolink.exec(e))e=e.substring(l[0].length),h=l[0],i="@"===l[2]?"mailto:"+(r=j(this.options.mangle?this.mangle(l[1]):l[1])):r=j(l[1]),t.push({type:"link",raw:h,text:r,href:i,tokens:[{type:"text",raw:r,text:r}]}),p+=r;else if(this.inLink||!(l=this.rules.inline.url.exec(e))){if(l=this.rules.inline.text.exec(e))e=e.substring(l[0].length),h=l[0],r=this.inRawBlock?this.options.sanitize?this.options.sanitizer?this.options.sanitizer(l[0]):j(l[0]):l[0]:j(this.options.smartypants?this.smartypants(l[0]):l[0]),t.push({type:"text",raw:h,text:r}),p+=r;else if(e){var g="Infinite loop on byte: "+e.charCodeAt(0);if(!this.options.silent)throw new Error(g);console.error(g)}}else{if("@"===l[2])i="mailto:"+(r=j(this.options.mangle?this.mangle(l[0]):l[0]));else{do{o=l[0],l[0]=this.rules.inline._backpedal.exec(l[0])[0]}while(o!==l[0]);r=j(l[0]),i="www."===l[1]?"http://"+r:r}e=e.substring(l[0].length),h=l[0],t.push({type:"link",raw:h,text:r,href:i,tokens:[{type:"text",raw:r,text:r}]}),p+=r}return p}},{key:"escapes",value:function(e){return e?e.replace(N._escapes,"$1"):e}},{key:"outputLink",value:function(e,t,n,r){var s=t.href,i=t.title?j(t.title):null,a=n?[]:null;if("!"!==e[0].charAt(0)){var l=this.inlineTokens(e[1],a);return n.push({type:"link",raw:r,text:l,href:s,title:i,tokens:a}),l}var o=j(e[1]);return n.push({type:"image",raw:r,text:o,href:s,title:i}),o}},{key:"smartypants",value:function(e){return e.replace(/---/g,"—").replace(/--/g,"–").replace(/(^|[-\u2014/(\[{"\s])'/g,"$1‘").replace(/'/g,"’").replace(/(^|[-\u2014/(\[{\u2018\s])"/g,"$1“").replace(/"/g,"”").replace(/\.{3}/g,"…")}},{key:"mangle",value:function(e){var t,n,r="",s=e.length;for(t=0;t.5&&(n="x"+n.toString(16)),r+="&#"+n+";";return r}}],[{key:"lex",value:function(t,n){return new e(n).lex(t)}},{key:"rules",get:function(){return{block:P,inline:N}}}]),e}(),U=s.defaults,F=S,V=w,X=function(){function e(n){t(this,e),this.options=n||U}return r(e,[{key:"code",value:function(e,t,n){var r=(t||"").match(/\S*/)[0];if(this.options.highlight){var s=this.options.highlight(e,r);null!=s&&s!==e&&(n=!0,e=s)}return r?'
    '+(n?e:V(e,!0))+"
    \n":"
    "+(n?e:V(e,!0))+"
    "}},{key:"blockquote",value:function(e){return"
    \n"+e+"
    \n"}},{key:"html",value:function(e){return e}},{key:"heading",value:function(e,t,n,r){return this.options.headerIds?"'+e+"\n":""+e+"\n"}},{key:"hr",value:function(){return this.options.xhtml?"
    \n":"
    \n"}},{key:"list",value:function(e,t,n){var r=t?"ol":"ul";return"<"+r+(t&&1!==n?' start="'+n+'"':"")+">\n"+e+"\n"}},{key:"listitem",value:function(e){return"
  • "+e+"
  • \n"}},{key:"checkbox",value:function(e){return" "}},{key:"paragraph",value:function(e){return"

    "+e+"

    \n"}},{key:"table",value:function(e,t){return t&&(t=""+t+""),"\n\n"+e+"\n"+t+"
    \n"}},{key:"tablerow",value:function(e){return"\n"+e+"\n"}},{key:"tablecell",value:function(e,t){var n=t.header?"th":"td";return(t.align?"<"+n+' align="'+t.align+'">':"<"+n+">")+e+"\n"}},{key:"strong",value:function(e){return""+e+""}},{key:"em",value:function(e){return""+e+""}},{key:"codespan",value:function(e){return""+e+""}},{key:"br",value:function(){return this.options.xhtml?"
    ":"
    "}},{key:"del",value:function(e){return""+e+""}},{key:"link",value:function(e,t,n){if(null===(e=F(this.options.sanitize,this.options.baseUrl,e)))return n;var r='
    "}},{key:"image",value:function(e,t,n){if(null===(e=F(this.options.sanitize,this.options.baseUrl,e)))return n;var r=''+n+'":">"}},{key:"text",value:function(e){return e}}]),e}(),G=function(){function e(){t(this,e)}return r(e,[{key:"strong",value:function(e){return e}},{key:"em",value:function(e){return e}},{key:"codespan",value:function(e){return e}},{key:"del",value:function(e){return e}},{key:"html",value:function(e){return e}},{key:"text",value:function(e){return e}},{key:"link",value:function(e,t,n){return""+n}},{key:"image",value:function(e,t,n){return""+n}},{key:"br",value:function(){return""}}]),e}(),J=function(){function e(){t(this,e),this.seen={}}return r(e,[{key:"slug",value:function(e){var t=e.toLowerCase().trim().replace(/<[!\/a-z].*?>/gi,"").replace(/[\u2000-\u206F\u2E00-\u2E7F\\'!"#$%&()*+,./:;<=>?@[\]^`{|}~]/g,"").replace(/\s/g,"-");if(this.seen.hasOwnProperty(t)){var n=t;do{this.seen[n]++,t=n+"-"+this.seen[n]}while(this.seen.hasOwnProperty(t))}return this.seen[t]=0,t}}]),e}(),K=s.defaults,Q=_,W=function(){function e(n){t(this,e),this.options=n||K,this.options.renderer=this.options.renderer||new X,this.renderer=this.options.renderer,this.renderer.options=this.options,this.textRenderer=new G,this.slugger=new J}return r(e,[{key:"parse",value:function(e){var t,n,r,s,i,a,l,o,c,u,h,p,g,f,d,b,k,m,x=!(arguments.length>1&&void 0!==arguments[1])||arguments[1],y="",v=e.length;for(t=0;t0&&"text"===d.tokens[0].tokens[0].type&&(d.tokens[0].tokens[0].text=m+" "+d.tokens[0].tokens[0].text)):d.tokens.unshift({type:"text",text:m}):f+=m),f+=this.parse(d.tokens,g),c+=this.renderer.listitem(f,k,b);y+=this.renderer.list(c,h,p);continue;case"html":y+=this.renderer.html(u.text);continue;case"paragraph":y+=this.renderer.paragraph(this.parseInline(u.tokens));continue;case"text":for(c=u.tokens?this.parseInline(u.tokens):u.text;t+1An error occurred:

    "+te(e.message+"",!0)+"
    ";throw e}}ie.options=ie.setOptions=function(e){return Y(ie.defaults,e),re(ie.defaults),ie},ie.getDefaults=ne,ie.defaults=se,ie.Parser=W,ie.parser=W.parse,ie.Renderer=X,ie.TextRenderer=G,ie.Lexer=B,ie.lexer=B.lex,ie.Slugger=J,ie.parse=ie;var ae=ie; /*! * The reveal.js markdown plugin. Handles parsing of * markdown inside of presentations as well as loading * of external markdown documents. - */function oe(e){var t=(e.querySelector("[data-template]")||e.querySelector("script")||e).textContent,n=(t=t.replace(new RegExp("__SCRIPT_END__","g"),"<\/script>")).match(/^\n?(\s*)/)[1].length,r=t.match(/^\n?(\t*)/)[1].length;return r>0?t=t.replace(new RegExp("\\n?\\t{"+r+"}","g"),"\n"):n>1&&(t=t.replace(new RegExp("\\n? {"+n+"}","g"),"\n")),t}function ce(e){for(var t=e.attributes,n=[],r=0,s=t.length;r'+ae(n[1].trim())+""),' + +
    +

    The Lorenz Equations

    + + \[\begin{aligned} + \dot{x} & = \sigma(y-x) \\ + \dot{y} & = \rho x - y - xz \\ + \dot{z} & = -\beta z + xy + \end{aligned} \] +
    + + + ' ); + + var leadingWs = text.match( /^\n?(\s*)/ )[1].length, + leadingTabs = text.match( /^\n?(\t*)/ )[1].length; + + if( leadingTabs > 0 ) { + text = text.replace( new RegExp('\\n?\\t{' + leadingTabs + '}','g'), '\n' ); + } + else if( leadingWs > 1 ) { + text = text.replace( new RegExp('\\n? {' + leadingWs + '}', 'g'), '\n' ); } - return processSlides( deck.getRevealElement() ).then( convertSlides ); + return text; - }, - - // TODO: Do these belong in the API? - processSlides: processSlides, - convertSlides: convertSlides, - slidify: slidify, - marked: marked - -}; - -export default () => Plugin; - -var DEFAULT_SLIDE_SEPARATOR = '^\r?\n---\r?\n$', - DEFAULT_NOTES_SEPARATOR = 'notes?:', - DEFAULT_ELEMENT_ATTRIBUTES_SEPARATOR = '\\\.element\\\s*?(.+?)$', - DEFAULT_SLIDE_ATTRIBUTES_SEPARATOR = '\\\.slide:\\\s*?(\\\S.+?)$'; - -var SCRIPT_END_PLACEHOLDER = '__SCRIPT_END__'; - - -/** - * Retrieves the markdown contents of a slide section - * element. Normalizes leading tabs/whitespace. - */ -function getMarkdownFromSlide( section ) { - - // look for a ' ); - - var leadingWs = text.match( /^\n?(\s*)/ )[1].length, - leadingTabs = text.match( /^\n?(\t*)/ )[1].length; - - if( leadingTabs > 0 ) { - text = text.replace( new RegExp('\\n?\\t{' + leadingTabs + '}','g'), '\n' ); - } - else if( leadingWs > 1 ) { - text = text.replace( new RegExp('\\n? {' + leadingWs + '}', 'g'), '\n' ); } - return text; + /** + * Given a markdown slide section element, this will + * return all arguments that aren't related to markdown + * parsing. Used to forward any other user-defined arguments + * to the output markdown slide. + */ + function getForwardedAttributes( section ) { -} + var attributes = section.attributes; + var result = []; -/** - * Given a markdown slide section element, this will - * return all arguments that aren't related to markdown - * parsing. Used to forward any other user-defined arguments - * to the output markdown slide. - */ -function getForwardedAttributes( section ) { + for( var i = 0, len = attributes.length; i < len; i++ ) { + var name = attributes[i].name, + value = attributes[i].value; - var attributes = section.attributes; - var result = []; - - for( var i = 0, len = attributes.length; i < len; i++ ) { - var name = attributes[i].name, - value = attributes[i].value; - - // disregard attributes that are used for markdown loading/parsing - if( /data\-(markdown|separator|vertical|notes)/gi.test( name ) ) continue; - - if( value ) { - result.push( name + '="' + value + '"' ); - } - else { - result.push( name ); - } - } - - return result.join( ' ' ); - -} - -/** - * Inspects the given options and fills out default - * values for what's not defined. - */ -function getSlidifyOptions( options ) { - - options = options || {}; - options.separator = options.separator || DEFAULT_SLIDE_SEPARATOR; - options.notesSeparator = options.notesSeparator || DEFAULT_NOTES_SEPARATOR; - options.attributes = options.attributes || ''; - - return options; - -} - -/** - * Helper function for constructing a markdown slide. - */ -function createMarkdownSlide( content, options ) { - - options = getSlidifyOptions( options ); - - var notesMatch = content.split( new RegExp( options.notesSeparator, 'mgi' ) ); - - if( notesMatch.length === 2 ) { - content = notesMatch[0] + ''; - } - - // prevent script end tags in the content from interfering - // with parsing - content = content.replace( /<\/script>/g, SCRIPT_END_PLACEHOLDER ); - - return ''; - -} - -/** - * Parses a data string into multiple slides based - * on the passed in separator arguments. - */ -function slidify( markdown, options ) { - - options = getSlidifyOptions( options ); - - var separatorRegex = new RegExp( options.separator + ( options.verticalSeparator ? '|' + options.verticalSeparator : '' ), 'mg' ), - horizontalSeparatorRegex = new RegExp( options.separator ); - - var matches, - lastIndex = 0, - isHorizontal, - wasHorizontal = true, - content, - sectionStack = []; - - // iterate until all blocks between separators are stacked up - while( matches = separatorRegex.exec( markdown ) ) { - var notes = null; - - // determine direction (horizontal by default) - isHorizontal = horizontalSeparatorRegex.test( matches[0] ); - - if( !isHorizontal && wasHorizontal ) { - // create vertical stack - sectionStack.push( [] ); - } - - // pluck slide content from markdown input - content = markdown.substring( lastIndex, matches.index ); - - if( isHorizontal && wasHorizontal ) { - // add to horizontal stack - sectionStack.push( content ); - } - else { - // add to vertical stack - sectionStack[sectionStack.length-1].push( content ); - } - - lastIndex = separatorRegex.lastIndex; - wasHorizontal = isHorizontal; - } - - // add the remaining slide - ( wasHorizontal ? sectionStack : sectionStack[sectionStack.length-1] ).push( markdown.substring( lastIndex ) ); - - var markdownSections = ''; - - // flatten the hierarchical stack, and insert
    tags - for( var i = 0, len = sectionStack.length; i < len; i++ ) { - // vertical - if( sectionStack[i] instanceof Array ) { - markdownSections += '
    '; - - sectionStack[i].forEach( function( child ) { - markdownSections += '
    ' + createMarkdownSlide( child, options ) + '
    '; - } ); - - markdownSections += '
    '; - } - else { - markdownSections += '
    ' + createMarkdownSlide( sectionStack[i], options ) + '
    '; - } - } - - return markdownSections; - -} - -/** - * Parses any current data-markdown slides, splits - * multi-slide markdown into separate sections and - * handles loading of external markdown. - */ -function processSlides( scope ) { - - return new Promise( function( resolve ) { - - var externalPromises = []; - - [].slice.call( scope.querySelectorAll( '[data-markdown]:not([data-markdown-parsed])') ).forEach( function( section, i ) { - - if( section.getAttribute( 'data-markdown' ).length ) { - - externalPromises.push( loadExternalMarkdown( section ).then( - - // Finished loading external file - function( xhr, url ) { - section.outerHTML = slidify( xhr.responseText, { - separator: section.getAttribute( 'data-separator' ), - verticalSeparator: section.getAttribute( 'data-separator-vertical' ), - notesSeparator: section.getAttribute( 'data-separator-notes' ), - attributes: getForwardedAttributes( section ) - }); - }, - - // Failed to load markdown - function( xhr, url ) { - section.outerHTML = '
    ' + - 'ERROR: The attempt to fetch ' + url + ' failed with HTTP status ' + xhr.status + '.' + - 'Check your browser\'s JavaScript console for more details.' + - '

    Remember that you need to serve the presentation HTML from a HTTP server.

    ' + - '
    '; - } - - ) ); - - } - else if( section.getAttribute( 'data-separator' ) || section.getAttribute( 'data-separator-vertical' ) || section.getAttribute( 'data-separator-notes' ) ) { - - section.outerHTML = slidify( getMarkdownFromSlide( section ), { - separator: section.getAttribute( 'data-separator' ), - verticalSeparator: section.getAttribute( 'data-separator-vertical' ), - notesSeparator: section.getAttribute( 'data-separator-notes' ), - attributes: getForwardedAttributes( section ) - }); + // disregard attributes that are used for markdown loading/parsing + if( /data\-(markdown|separator|vertical|notes)/gi.test( name ) ) continue; + if( value ) { + result.push( name + '="' + value + '"' ); } else { - section.innerHTML = createMarkdownSlide( getMarkdownFromSlide( section ) ); + result.push( name ); } - - }); - - Promise.all( externalPromises ).then( resolve ); - - } ); - -} - -function loadExternalMarkdown( section ) { - - return new Promise( function( resolve, reject ) { - - var xhr = new XMLHttpRequest(), - url = section.getAttribute( 'data-markdown' ); - - var datacharset = section.getAttribute( 'data-charset' ); - - // see https://developer.mozilla.org/en-US/docs/Web/API/element.getAttribute#Notes - if( datacharset != null && datacharset != '' ) { - xhr.overrideMimeType( 'text/html; charset=' + datacharset ); } - xhr.onreadystatechange = function( section, xhr ) { - if( xhr.readyState === 4 ) { - // file protocol yields status code 0 (useful for local debug, mobile applications etc.) - if ( ( xhr.status >= 200 && xhr.status < 300 ) || xhr.status === 0 ) { + return result.join( ' ' ); - resolve( xhr, url ); + } + + /** + * Inspects the given options and fills out default + * values for what's not defined. + */ + function getSlidifyOptions( options ) { + + options = options || {}; + options.separator = options.separator || DEFAULT_SLIDE_SEPARATOR; + options.notesSeparator = options.notesSeparator || DEFAULT_NOTES_SEPARATOR; + options.attributes = options.attributes || ''; + + return options; + + } + + /** + * Helper function for constructing a markdown slide. + */ + function createMarkdownSlide( content, options ) { + + options = getSlidifyOptions( options ); + + var notesMatch = content.split( new RegExp( options.notesSeparator, 'mgi' ) ); + + if( notesMatch.length === 2 ) { + content = notesMatch[0] + ''; + } + + // prevent script end tags in the content from interfering + // with parsing + content = content.replace( /<\/script>/g, SCRIPT_END_PLACEHOLDER ); + + return ''; + + } + + /** + * Parses a data string into multiple slides based + * on the passed in separator arguments. + */ + function slidify( markdown, options ) { + + options = getSlidifyOptions( options ); + + var separatorRegex = new RegExp( options.separator + ( options.verticalSeparator ? '|' + options.verticalSeparator : '' ), 'mg' ), + horizontalSeparatorRegex = new RegExp( options.separator ); + + var matches, + lastIndex = 0, + isHorizontal, + wasHorizontal = true, + content, + sectionStack = []; + + // iterate until all blocks between separators are stacked up + while( matches = separatorRegex.exec( markdown ) ) { + var notes = null; + + // determine direction (horizontal by default) + isHorizontal = horizontalSeparatorRegex.test( matches[0] ); + + if( !isHorizontal && wasHorizontal ) { + // create vertical stack + sectionStack.push( [] ); + } + + // pluck slide content from markdown input + content = markdown.substring( lastIndex, matches.index ); + + if( isHorizontal && wasHorizontal ) { + // add to horizontal stack + sectionStack.push( content ); + } + else { + // add to vertical stack + sectionStack[sectionStack.length-1].push( content ); + } + + lastIndex = separatorRegex.lastIndex; + wasHorizontal = isHorizontal; + } + + // add the remaining slide + ( wasHorizontal ? sectionStack : sectionStack[sectionStack.length-1] ).push( markdown.substring( lastIndex ) ); + + var markdownSections = ''; + + // flatten the hierarchical stack, and insert
    tags + for( var i = 0, len = sectionStack.length; i < len; i++ ) { + // vertical + if( sectionStack[i] instanceof Array ) { + markdownSections += '
    '; + + sectionStack[i].forEach( function( child ) { + markdownSections += '
    ' + createMarkdownSlide( child, options ) + '
    '; + } ); + + markdownSections += '
    '; + } + else { + markdownSections += '
    ' + createMarkdownSlide( sectionStack[i], options ) + '
    '; + } + } + + return markdownSections; + + } + + /** + * Parses any current data-markdown slides, splits + * multi-slide markdown into separate sections and + * handles loading of external markdown. + */ + function processSlides( scope ) { + + return new Promise( function( resolve ) { + + var externalPromises = []; + + [].slice.call( scope.querySelectorAll( '[data-markdown]:not([data-markdown-parsed])') ).forEach( function( section, i ) { + + if( section.getAttribute( 'data-markdown' ).length ) { + + externalPromises.push( loadExternalMarkdown( section ).then( + + // Finished loading external file + function( xhr, url ) { + section.outerHTML = slidify( xhr.responseText, { + separator: section.getAttribute( 'data-separator' ), + verticalSeparator: section.getAttribute( 'data-separator-vertical' ), + notesSeparator: section.getAttribute( 'data-separator-notes' ), + attributes: getForwardedAttributes( section ) + }); + }, + + // Failed to load markdown + function( xhr, url ) { + section.outerHTML = '
    ' + + 'ERROR: The attempt to fetch ' + url + ' failed with HTTP status ' + xhr.status + '.' + + 'Check your browser\'s JavaScript console for more details.' + + '

    Remember that you need to serve the presentation HTML from a HTTP server.

    ' + + '
    '; + } + + ) ); + + } + else if( section.getAttribute( 'data-separator' ) || section.getAttribute( 'data-separator-vertical' ) || section.getAttribute( 'data-separator-notes' ) ) { + + section.outerHTML = slidify( getMarkdownFromSlide( section ), { + separator: section.getAttribute( 'data-separator' ), + verticalSeparator: section.getAttribute( 'data-separator-vertical' ), + notesSeparator: section.getAttribute( 'data-separator-notes' ), + attributes: getForwardedAttributes( section ) + }); } else { - - reject( xhr, url ); - + section.innerHTML = createMarkdownSlide( getMarkdownFromSlide( section ) ); } - } - }.bind( this, section, xhr ); - xhr.open( 'GET', url, true ); + }); - try { - xhr.send(); - } - catch ( e ) { - 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 ); - resolve( xhr, url ); - } + Promise.all( externalPromises ).then( resolve ); - } ); + } ); -} - -/** - * Check if a node value has the attributes pattern. - * If yes, extract it and add that value as one or several attributes - * to the target element. - * - * You need Cache Killer on Chrome to see the effect on any FOM transformation - * directly on refresh (F5) - * http://stackoverflow.com/questions/5690269/disabling-chrome-cache-for-website-development/7000899#answer-11786277 - */ -function addAttributeInElement( node, elementTarget, separator ) { - - var mardownClassesInElementsRegex = new RegExp( separator, 'mg' ); - var mardownClassRegex = new RegExp( "([^\"= ]+?)=\"([^\"]+?)\"|(data-[^\"= ]+?)(?=[\" ])", 'mg' ); - var nodeValue = node.nodeValue; - var matches, - matchesClass; - if( matches = mardownClassesInElementsRegex.exec( nodeValue ) ) { - - var classes = matches[1]; - nodeValue = nodeValue.substring( 0, matches.index ) + nodeValue.substring( mardownClassesInElementsRegex.lastIndex ); - node.nodeValue = nodeValue; - while( matchesClass = mardownClassRegex.exec( classes ) ) { - if( matchesClass[2] ) { - elementTarget.setAttribute( matchesClass[1], matchesClass[2] ); - } else { - elementTarget.setAttribute( matchesClass[3], "" ); - } - } - return true; } - return false; -} -/** - * Add attributes to the parent element of a text node, - * or the element of an attribute node. - */ -function addAttributes( section, element, previousElement, separatorElementAttributes, separatorSectionAttributes ) { + function loadExternalMarkdown( section ) { + + return new Promise( function( resolve, reject ) { + + var xhr = new XMLHttpRequest(), + url = section.getAttribute( 'data-markdown' ); + + var datacharset = section.getAttribute( 'data-charset' ); + + // see https://developer.mozilla.org/en-US/docs/Web/API/element.getAttribute#Notes + if( datacharset != null && datacharset != '' ) { + xhr.overrideMimeType( 'text/html; charset=' + datacharset ); + } + + xhr.onreadystatechange = function( section, xhr ) { + if( xhr.readyState === 4 ) { + // file protocol yields status code 0 (useful for local debug, mobile applications etc.) + if ( ( xhr.status >= 200 && xhr.status < 300 ) || xhr.status === 0 ) { + + resolve( xhr, url ); - if ( element != null && element.childNodes != undefined && element.childNodes.length > 0 ) { - var previousParentElement = element; - for( var i = 0; i < element.childNodes.length; i++ ) { - var childElement = element.childNodes[i]; - if ( i > 0 ) { - var j = i - 1; - while ( j >= 0 ) { - var aPreviousChildElement = element.childNodes[j]; - if ( typeof aPreviousChildElement.setAttribute == 'function' && aPreviousChildElement.tagName != "BR" ) { - previousParentElement = aPreviousChildElement; - break; } - j = j - 1; + else { + + reject( xhr, url ); + + } + } + }.bind( this, section, xhr ); + + xhr.open( 'GET', url, true ); + + try { + xhr.send(); + } + catch ( e ) { + 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 ); + resolve( xhr, url ); + } + + } ); + + } + + /** + * Check if a node value has the attributes pattern. + * If yes, extract it and add that value as one or several attributes + * to the target element. + * + * You need Cache Killer on Chrome to see the effect on any FOM transformation + * directly on refresh (F5) + * http://stackoverflow.com/questions/5690269/disabling-chrome-cache-for-website-development/7000899#answer-11786277 + */ + function addAttributeInElement( node, elementTarget, separator ) { + + var mardownClassesInElementsRegex = new RegExp( separator, 'mg' ); + var mardownClassRegex = new RegExp( "([^\"= ]+?)=\"([^\"]+?)\"|(data-[^\"= ]+?)(?=[\" ])", 'mg' ); + var nodeValue = node.nodeValue; + var matches, + matchesClass; + if( matches = mardownClassesInElementsRegex.exec( nodeValue ) ) { + + var classes = matches[1]; + nodeValue = nodeValue.substring( 0, matches.index ) + nodeValue.substring( mardownClassesInElementsRegex.lastIndex ); + node.nodeValue = nodeValue; + while( matchesClass = mardownClassRegex.exec( classes ) ) { + if( matchesClass[2] ) { + elementTarget.setAttribute( matchesClass[1], matchesClass[2] ); + } else { + elementTarget.setAttribute( matchesClass[3], "" ); } } - var parentSection = section; - if( childElement.nodeName == "section" ) { - parentSection = childElement ; - previousParentElement = childElement ; + return true; + } + return false; + } + + /** + * Add attributes to the parent element of a text node, + * or the element of an attribute node. + */ + function addAttributes( section, element, previousElement, separatorElementAttributes, separatorSectionAttributes ) { + + if ( element != null && element.childNodes != undefined && element.childNodes.length > 0 ) { + var previousParentElement = element; + for( var i = 0; i < element.childNodes.length; i++ ) { + var childElement = element.childNodes[i]; + if ( i > 0 ) { + var j = i - 1; + while ( j >= 0 ) { + var aPreviousChildElement = element.childNodes[j]; + if ( typeof aPreviousChildElement.setAttribute == 'function' && aPreviousChildElement.tagName != "BR" ) { + previousParentElement = aPreviousChildElement; + break; + } + j = j - 1; + } + } + var parentSection = section; + if( childElement.nodeName == "section" ) { + parentSection = childElement ; + previousParentElement = childElement ; + } + if ( typeof childElement.setAttribute == 'function' || childElement.nodeType == Node.COMMENT_NODE ) { + addAttributes( parentSection, childElement, previousParentElement, separatorElementAttributes, separatorSectionAttributes ); + } } - if ( typeof childElement.setAttribute == 'function' || childElement.nodeType == Node.COMMENT_NODE ) { - addAttributes( parentSection, childElement, previousParentElement, separatorElementAttributes, separatorSectionAttributes ); + } + + if ( element.nodeType == Node.COMMENT_NODE ) { + if ( addAttributeInElement( element, previousElement, separatorElementAttributes ) == false ) { + addAttributeInElement( element, section, separatorSectionAttributes ); } } } - if ( element.nodeType == Node.COMMENT_NODE ) { - if ( addAttributeInElement( element, previousElement, separatorElementAttributes ) == false ) { - addAttributeInElement( element, section, separatorSectionAttributes ); - } + /** + * Converts any current data-markdown slides in the + * DOM to HTML. + */ + function convertSlides() { + + var sections = deck.getRevealElement().querySelectorAll( '[data-markdown]:not([data-markdown-parsed])'); + + [].slice.call( sections ).forEach( function( section ) { + + section.setAttribute( 'data-markdown-parsed', true ) + + var notes = section.querySelector( 'aside.notes' ); + var markdown = getMarkdownFromSlide( section ); + + section.innerHTML = marked( markdown ); + addAttributes( section, section, null, section.getAttribute( 'data-element-attributes' ) || + section.parentNode.getAttribute( 'data-element-attributes' ) || + DEFAULT_ELEMENT_ATTRIBUTES_SEPARATOR, + section.getAttribute( 'data-attributes' ) || + section.parentNode.getAttribute( 'data-attributes' ) || + DEFAULT_SLIDE_ATTRIBUTES_SEPARATOR); + + // If there were notes, we need to re-add them after + // having overwritten the section's HTML + if( notes ) { + section.appendChild( notes ); + } + + } ); + + return Promise.resolve(); + } -} -/** - * Converts any current data-markdown slides in the - * DOM to HTML. - */ -function convertSlides() { + return { + id: 'markdown', - var sections = document.querySelectorAll( '[data-markdown]:not([data-markdown-parsed])'); + /** + * Starts processing and converting Markdown within the + * current reveal.js deck. + */ + init: function( reveal ) { - [].slice.call( sections ).forEach( function( section ) { + deck = reveal; - section.setAttribute( 'data-markdown-parsed', true ) + // This should no longer be needed, as long as the highlight.js + // plugin is included after the markdown plugin + // if( typeof window.hljs !== 'undefined' ) { + // marked.setOptions({ + // highlight: function( code, lang ) { + // return window.hljs.highlightAuto( code, lang ? [lang] : null ).value; + // } + // }); + // } - var notes = section.querySelector( 'aside.notes' ); - var markdown = getMarkdownFromSlide( section ); + // marked can be configured via reveal.js config options + var options = deck.getConfig().markdown; + if( options ) { + marked.setOptions( options ); + } - section.innerHTML = marked( markdown ); - addAttributes( section, section, null, section.getAttribute( 'data-element-attributes' ) || - section.parentNode.getAttribute( 'data-element-attributes' ) || - DEFAULT_ELEMENT_ATTRIBUTES_SEPARATOR, - section.getAttribute( 'data-attributes' ) || - section.parentNode.getAttribute( 'data-attributes' ) || - DEFAULT_SLIDE_ATTRIBUTES_SEPARATOR); + return processSlides( deck.getRevealElement() ).then( convertSlides ); - // If there were notes, we need to re-add them after - // having overwritten the section's HTML - if( notes ) { - section.appendChild( notes ); - } + }, - } ); + // TODO: Do these belong in the API? + processSlides: processSlides, + convertSlides: convertSlides, + slidify: slidify, + marked: marked + } - return Promise.resolve(); +}; -} +export default Plugin; diff --git a/plugin/math/math.js b/plugin/math/math.js index 25f50cb..eaef379 100755 --- a/plugin/math/math.js +++ b/plugin/math/math.js @@ -4,14 +4,12 @@ * * @author Hakim El Hattab */ -let Plugin = (function(){ +const Plugin = () => { - var options = Reveal.getConfig().math || {}; - var mathjax = options.mathjax || 'https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.0/MathJax.js'; - var config = options.config || 'TeX-AMS_HTML-full'; - var url = mathjax + '?config=' + config; + // The reveal.js instance this plugin is attached to + let deck; - var defaultOptions = { + let defaultOptions = { messageStyle: 'none', tex2jax: { inlineMath: [ [ '$', '$' ], [ '\\(', '\\)' ] ], @@ -20,25 +18,15 @@ let Plugin = (function(){ skipStartupTypeset: true }; - function defaults( options, defaultOptions ) { - - for ( var i in defaultOptions ) { - if ( !options.hasOwnProperty( i ) ) { - options[i] = defaultOptions[i]; - } - } - - } - function loadScript( url, callback ) { - var head = document.querySelector( 'head' ); - var script = document.createElement( 'script' ); + let head = document.querySelector( 'head' ); + let script = document.createElement( 'script' ); script.type = 'text/javascript'; script.src = url; // Wrapper for callback to make sure it only fires once - var finish = function() { + let finish = () => { if( typeof callback === 'function' ) { callback.call(); callback = null; @@ -48,7 +36,7 @@ let Plugin = (function(){ script.onload = finish; // IE - script.onreadystatechange = function() { + script.onreadystatechange = () => { if ( this.readyState === 'loaded' ) { finish(); } @@ -62,10 +50,19 @@ let Plugin = (function(){ return { id: 'math', - init: function( deck ) { + init: function( reveal ) { + + deck = reveal; + + let revealOptions = deck.getConfig().math || {}; + + let options = { ...defaultOptions, ...revealOptions }; + let mathjax = options.mathjax || 'https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.0/MathJax.js'; + let config = options.config || 'TeX-AMS_HTML-full'; + let url = mathjax + '?config=' + config; + + options.tex2jax = { ...defaultOptions.tex2jax, ...revealOptions.tex2jax }; - defaults( options, defaultOptions ); - defaults( options.tex2jax, defaultOptions.tex2jax ); options.mathjax = options.config = null; loadScript( url, function() { @@ -74,7 +71,7 @@ let Plugin = (function(){ // Typeset followed by an immediate reveal.js layout since // the typesetting process could affect slide height - MathJax.Hub.Queue( [ 'Typeset', MathJax.Hub ] ); + MathJax.Hub.Queue( [ 'Typeset', MathJax.Hub, deck.getRevealElement() ] ); MathJax.Hub.Queue( deck.layout ); // Reprocess equations in slides when they turn visible @@ -89,6 +86,6 @@ let Plugin = (function(){ } } -})(); +}; -export default () => Plugin; +export default Plugin; diff --git a/plugin/search/search.js b/plugin/search/search.js index cc39ef0..5d09ce6 100644 --- a/plugin/search/search.js +++ b/plugin/search/search.js @@ -2,130 +2,89 @@ * Handles finding a text string anywhere in the slides and showing the next occurrence to the user * by navigatating to that slide and highlighting it. * - * By Jon Snyder , February 2013 + * @author Jon Snyder , February 2013 */ -var Plugin = (function() { +const Plugin = () => { - var matchedSlides; - var currentMatchedIndex; - var searchboxDirty; - var myHilitor; + // The reveal.js instance this plugin is attached to + let deck; -// Original JavaScript code by Chirp Internet: www.chirp.com.au -// Please acknowledge use of this code by including this header. -// 2/2013 jon: modified regex to display any match, not restricted to word boundaries. + let searchElement; + let searchButton; + let searchInput; -function Hilitor(id, tag) -{ + let matchedSlides; + let currentMatchedIndex; + let searchboxDirty; + let hilitor; - var targetNode = document.getElementById(id) || document.body; - var hiliteTag = tag || "EM"; - var skipTags = new RegExp("^(?:" + hiliteTag + "|SCRIPT|FORM)$"); - var colors = ["#ff6", "#a0ffff", "#9f9", "#f99", "#f6f"]; - var wordColor = []; - var colorIdx = 0; - var matchRegex = ""; - var matchingSlides = []; + function render() { - this.setRegex = function(input) - { - input = input.replace(/^[^\w]+|[^\w]+$/g, "").replace(/[^\w'-]+/g, "|"); - matchRegex = new RegExp("(" + input + ")","i"); - } + searchElement = document.createElement( 'div' ); + searchElement.classList.add( 'searchbox' ); + searchElement.style.position = 'absolute'; + searchElement.style.top = '10px'; + searchElement.style.right = '10px'; + searchElement.style.zIndex = 10; - this.getRegex = function() - { - return matchRegex.toString().replace(/^\/\\b\(|\)\\b\/i$/g, "").replace(/\|/g, " "); - } + //embedded base64 search icon Designed by Sketchdock - http://www.sketchdock.com/: + searchElement.innerHTML = ` + `; - // recursively apply word highlighting - this.hiliteWords = function(node) - { - if(node == undefined || !node) return; - if(!matchRegex) return; - if(skipTags.test(node.nodeName)) return; + searchInput = searchElement.querySelector( '.searchinput' ); + searchInput.style.width = '240px'; + searchInput.style.fontSize = '14px'; + searchInput.style.padding = '4px 6px'; + searchInput.style.color = '#000'; + searchInput.style.background = '#fff'; + searchInput.style.borderRadius = '2px'; + searchInput.style.border = '0'; + searchInput.style.outline = '0'; + searchInput.style.boxShadow = '0 2px 18px rgba(0, 0, 0, 0.2)'; + searchInput.style['-webkit-appearance'] = 'none'; - if(node.hasChildNodes()) { - for(var i=0; i < node.childNodes.length; i++) - this.hiliteWords(node.childNodes[i]); - } - if(node.nodeType == 3) { // NODE_TEXT - if((nv = node.nodeValue) && (regs = matchRegex.exec(nv))) { - //find the slide's section element and save it in our list of matching slides - var secnode = node; - while (secnode != null && secnode.nodeName != 'SECTION') { - secnode = secnode.parentNode; - } + deck.getRevealElement().appendChild( searchElement ); - var slideIndex = Reveal.getIndices(secnode); - var slidelen = matchingSlides.length; - var alreadyAdded = false; - for (var i=0; i < slidelen; i++) { - if ( (matchingSlides[i].h === slideIndex.h) && (matchingSlides[i].v === slideIndex.v) ) { - alreadyAdded = true; - } - } - if (! alreadyAdded) { - matchingSlides.push(slideIndex); - } + // searchButton.addEventListener( 'click', function(event) { + // doSearch(); + // }, false ); - if(!wordColor[regs[0].toLowerCase()]) { - wordColor[regs[0].toLowerCase()] = colors[colorIdx++ % colors.length]; - } - - var match = document.createElement(hiliteTag); - match.appendChild(document.createTextNode(regs[0])); - match.style.backgroundColor = wordColor[regs[0].toLowerCase()]; - match.style.fontStyle = "inherit"; - match.style.color = "#000"; - - var after = node.splitText(regs.index); - after.nodeValue = after.nodeValue.substring(regs[0].length); - node.parentNode.insertBefore(match, after); + searchInput.addEventListener( 'keyup', function( event ) { + switch (event.keyCode) { + case 13: + event.preventDefault(); + doSearch(); + searchboxDirty = false; + break; + default: + searchboxDirty = true; } - } - }; + }, false ); - // remove highlighting - this.remove = function() - { - var arr = document.getElementsByTagName(hiliteTag); - while(arr.length && (el = arr[0])) { - el.parentNode.replaceChild(el.firstChild, el); - } - }; + closeSearch(); - // start highlighting at target node - this.apply = function(input) - { - if(input == undefined || !input) return; - this.remove(); - this.setRegex(input); - this.hiliteWords(targetNode); - return matchingSlides; - }; - -} + } function openSearch() { - //ensure the search term input dialog is visible and has focus: - var inputboxdiv = document.getElementById("searchinputdiv"); - var inputbox = document.getElementById("searchinput"); - inputboxdiv.style.display = "inline"; - inputbox.focus(); - inputbox.select(); + if( !searchElement ) render(); + + searchElement.style.display = 'inline'; + searchInput.focus(); + searchInput.select(); } function closeSearch() { - var inputboxdiv = document.getElementById("searchinputdiv"); - inputboxdiv.style.display = "none"; - if(myHilitor) myHilitor.remove(); + if( !searchElement ) render(); + + searchElement.style.display = 'none'; + if(hilitor) hilitor.remove(); } function toggleSearch() { - var inputboxdiv = document.getElementById("searchinputdiv"); - if (inputboxdiv.style.display !== "inline") { + if( !searchElement ) render(); + + if (searchElement.style.display !== 'inline') { openSearch(); } else { @@ -136,16 +95,16 @@ function Hilitor(id, tag) function doSearch() { //if there's been a change in the search term, perform a new search: if (searchboxDirty) { - var searchstring = document.getElementById("searchinput").value; + var searchstring = searchInput.value; if (searchstring === '') { - if(myHilitor) myHilitor.remove(); + if(hilitor) hilitor.remove(); matchedSlides = null; } else { //find the keyword amongst the slides - myHilitor = new Hilitor("slidecontent"); - matchedSlides = myHilitor.apply(searchstring); + hilitor = new Hilitor("slidecontent"); + matchedSlides = hilitor.apply(searchstring); currentMatchedIndex = 0; } } @@ -156,66 +115,129 @@ function Hilitor(id, tag) currentMatchedIndex = 0; } if (matchedSlides.length > currentMatchedIndex) { - Reveal.slide(matchedSlides[currentMatchedIndex].h, matchedSlides[currentMatchedIndex].v); + deck.slide(matchedSlides[currentMatchedIndex].h, matchedSlides[currentMatchedIndex].v); currentMatchedIndex++; } } } - var dom = {}; - dom.wrapper = document.querySelector( '.reveal' ); + // Original JavaScript code by Chirp Internet: www.chirp.com.au + // Please acknowledge use of this code by including this header. + // 2/2013 jon: modified regex to display any match, not restricted to word boundaries. + function Hilitor(id, tag) { + + var targetNode = document.getElementById(id) || document.body; + var hiliteTag = tag || "EM"; + var skipTags = new RegExp("^(?:" + hiliteTag + "|SCRIPT|FORM)$"); + var colors = ["#ff6", "#a0ffff", "#9f9", "#f99", "#f6f"]; + var wordColor = []; + var colorIdx = 0; + var matchRegex = ""; + var matchingSlides = []; + + this.setRegex = function(input) + { + input = input.replace(/^[^\w]+|[^\w]+$/g, "").replace(/[^\w'-]+/g, "|"); + matchRegex = new RegExp("(" + input + ")","i"); + } + + this.getRegex = function() + { + return matchRegex.toString().replace(/^\/\\b\(|\)\\b\/i$/g, "").replace(/\|/g, " "); + } + + // recursively apply word highlighting + this.hiliteWords = function(node) + { + if(node == undefined || !node) return; + if(!matchRegex) return; + if(skipTags.test(node.nodeName)) return; + + if(node.hasChildNodes()) { + for(var i=0; i < node.childNodes.length; i++) + this.hiliteWords(node.childNodes[i]); + } + if(node.nodeType == 3) { // NODE_TEXT + var nv, regs; + if((nv = node.nodeValue) && (regs = matchRegex.exec(nv))) { + //find the slide's section element and save it in our list of matching slides + var secnode = node; + while (secnode != null && secnode.nodeName != 'SECTION') { + secnode = secnode.parentNode; + } + + var slideIndex = deck.getIndices(secnode); + var slidelen = matchingSlides.length; + var alreadyAdded = false; + for (var i=0; i < slidelen; i++) { + if ( (matchingSlides[i].h === slideIndex.h) && (matchingSlides[i].v === slideIndex.v) ) { + alreadyAdded = true; + } + } + if (! alreadyAdded) { + matchingSlides.push(slideIndex); + } + + if(!wordColor[regs[0].toLowerCase()]) { + wordColor[regs[0].toLowerCase()] = colors[colorIdx++ % colors.length]; + } + + var match = document.createElement(hiliteTag); + match.appendChild(document.createTextNode(regs[0])); + match.style.backgroundColor = wordColor[regs[0].toLowerCase()]; + match.style.fontStyle = "inherit"; + match.style.color = "#000"; + + var after = node.splitText(regs.index); + after.nodeValue = after.nodeValue.substring(regs[0].length); + node.parentNode.insertBefore(match, after); + } + } + }; + + // remove highlighting + this.remove = function() + { + var arr = document.getElementsByTagName(hiliteTag); + var el; + while(arr.length && (el = arr[0])) { + el.parentNode.replaceChild(el.firstChild, el); + } + }; + + // start highlighting at target node + this.apply = function(input) + { + if(input == undefined || !input) return; + this.remove(); + this.setRegex(input); + this.hiliteWords(targetNode); + return matchingSlides; + }; - if( !dom.wrapper.querySelector( '.searchbox' ) ) { - var searchElement = document.createElement( 'div' ); - searchElement.id = "searchinputdiv"; - searchElement.classList.add( 'searchdiv' ); - searchElement.style.position = 'absolute'; - searchElement.style.top = '10px'; - searchElement.style.right = '10px'; - searchElement.style.zIndex = 10; - //embedded base64 search icon Designed by Sketchdock - http://www.sketchdock.com/: - searchElement.innerHTML = ''; - dom.wrapper.appendChild( searchElement ); } - document.getElementById( 'searchbutton' ).addEventListener( 'click', function(event) { - doSearch(); - }, false ); - - document.getElementById( 'searchinput' ).addEventListener( 'keyup', function( event ) { - switch (event.keyCode) { - case 13: - event.preventDefault(); - doSearch(); - searchboxDirty = false; - break; - default: - searchboxDirty = true; - } - }, false ); - - document.addEventListener( 'keydown', function( event ) { - if( event.key == "F" && (event.ctrlKey || event.metaKey) ) { //Control+Shift+f - event.preventDefault(); - toggleSearch(); - } - }, false ); - - closeSearch(); - return { id: 'search', init: reveal => { - reveal.registerKeyboardShortcut( 'CTRL + Shift + F', 'Search' ); + deck = reveal; + deck.registerKeyboardShortcut( 'CTRL + Shift + F', 'Search' ); + + document.addEventListener( 'keydown', function( event ) { + if( event.key == "F" && (event.ctrlKey || event.metaKey) ) { //Control+Shift+f + event.preventDefault(); + toggleSearch(); + } + }, false ); }, open: openSearch } -})(); +}; -export default () => Plugin; \ No newline at end of file +export default Plugin; \ No newline at end of file