lectures/_assets/plugin/markdown/markdown.js

8 lines
42 KiB
JavaScript
Raw Permalink Normal View History

!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):(e="undefined"!=typeof globalThis?globalThis:e||self).RevealMarkdown=t()}(this,(function(){"use strict";function e(){return{async:!1,baseUrl:null,breaks:!1,extensions:null,gfm:!0,headerIds:!0,headerPrefix:"",highlight:null,hooks:null,langPrefix:"language-",mangle:!0,pedantic:!1,renderer:null,sanitize:!1,sanitizer:null,silent:!1,smartypants:!1,tokenizer:null,walkTokens:null,xhtml:!1}}let t={async:!1,baseUrl:null,breaks:!1,extensions:null,gfm:!0,headerIds:!0,headerPrefix:"",highlight:null,hooks:null,langPrefix:"language-",mangle:!0,pedantic:!1,renderer:null,sanitize:!1,sanitizer:null,silent:!1,smartypants:!1,tokenizer:null,walkTokens:null,xhtml:!1};const n=/[&<>"']/,s=new RegExp(n.source,"g"),r=/[<>"']|&(?!(#\d{1,7}|#[Xx][a-fA-F0-9]{1,6}|\w+);)/,i=new RegExp(r.source,"g"),l={"&":"&amp;","<":"&lt;",">":"&gt;",'"':"&quot;","'":"&#39;"},o=e=>l[e];function a(e,t){if(t){if(n.test(e))return e.replace(s,o)}else if(r.test(e))return e.replace(i,o);return e}const c=/&(#(?:\d+)|(?:#x[0-9A-Fa-f]+)|(?:\w+));?/gi;function h(e){return e.replace(c,((e,t)=>"colon"===(t=t.toLowerCase())?":":"#"===t.charAt(0)?"x"===t.charAt(1)?String.fromCharCode(parseInt(t.substring(2),16)):String.fromCharCode(+t.substring(1)):""))}const p=/(^|[^\[])\^/g;function u(e,t){e="string"==typeof e?e:e.source,t=t||"";const n={replace:(t,s)=>(s=(s=s.source||s).replace(p,"$1"),e=e.replace(t,s),n),getRegex:()=>new RegExp(e,t)};return n}const g=/[^\w:]/g,d=/^$|^[a-z][a-z0-9+.-]*:|^[?#]/i;function f(e,t,n){if(e){let e;try{e=decodeURIComponent(h(n)).replace(g,"").toLowerCase()}catch(e){return null}if(0===e.indexOf("javascript:")||0===e.indexOf("vbscript:")||0===e.indexOf("data:"))return null}t&&!d.test(n)&&(n=function(e,t){k[" "+e]||(x.test(e)?k[" "+e]=e+"/":k[" "+e]=_(e,"/",!0));e=k[" "+e];const n=-1===e.indexOf(":");return"//"===t.substring(0,2)?n?t:e.replace(m,"$1")+t:"/"===t.charAt(0)?n?t:e.replace(b,"$1")+t:e+t}(t,n));try{n=encodeURI(n).replace(/%25/g,"%")}catch(e){return null}return n}const k={},x=/^[^:]+:\/*[^/]*$/,m=/^([^:]+:)[\s\S]*$/,b=/^([^:]+:\/*[^/]*)[\s\S]*$/;const w={exec:function(){}};function y(e,t){const n=e.replace(/\|/g,((e,t,n)=>{let s=!1,r=t;for(;--r>=0&&"\\"===n[r];)s=!s;return s?"|":" |"})).split(/ \|/);let s=0;if(n[0].trim()||n.shift(),n.length>0&&!n[n.length-1].trim()&&n.pop(),n.length>t)n.splice(t);else for(;n.length<t;)n.push("");for(;s<n.length;s++)n[s]=n[s].trim().replace(/\\\|/g,"|");return n}function _(e,t,n){const s=e.length;if(0===s)return"";let r=0;for(;r<s;){const i=e.charAt(s-r-1);if(i!==t||n){if(i===t||!n)break;r++}else r++}return e.slice(0,s-r)}function $(e,t){if(t<1)return"";let n="";for(;t>1;)1&t&&(n+=e),t>>=1,e+=e;return n+e}function z(e,t,n,s){const r=t.href,i=t.title?a(t.title):null,l=e[1].replace(/\\([\[\]])/g,"$1");if("!"!==e[0].charAt(0)){s.state.inLink=!0;const e={type:"link",raw:n,href:r,title:i,text:l,tokens:s.inlineTokens(l)};return s.state.inLink=!1,e}return{type:"image",raw:n,href:r,title:i,text:a(l)}}class S{constructor(e){this.options=e||t}space(e){const t=this.rules.block.newline.exec(e);if(t&&t[0].length>0)return{type:"space",raw:t[0]}}code(e){const t=this.rules.block.code.exec(e);if(t){const e=t[0].replace(/^ {1,4}/gm,"");return{type:"code",raw:t[0],codeBlockStyle:"indented",text:this.options.pedantic?e:_(e,"\n")}}}fences(e){const t=this.rules.block.fences.exec(e);if(t){const e=t[0],n=function(e,t){const n=e.match(/^(\s+)(?:```)/);if(null===n)return t;const s=n[1];return t.split("\n").map((e=>{const t=e.match(/^\s+/);if(null===t)return e;const[n]=t;return n.length>=s.length?e.slice(s.length):e})).join("\n")}(e,t[3]||"");return{type:"code",raw:e,lang:t[2]?t[2].trim().replace(this.rules.inline._escapes,"$1"):t[2],text:n}}}heading(e){const t=this.rules.block.heading.exec(e);if(t){let e=t[2].trim();if(/#$/.test(e)){const t=_(e,"#");this.options.pedantic?e=t.trim():t&&!/ $/.test(t)||(e=t.trim())}return{type:"heading",raw:t[0],depth:t[1].length,text:e,tokens:this.lexer.inline(e)}}}hr(e)
/*!
* The reveal.js markdown plugin. Handles parsing of
* markdown inside of presentations as well as loading
* of external markdown documents.
*/
const N="__SCRIPT_END__",O=/\[\s*((\d*):)?\s*([\s\d,|-]*)\]/,D={"&":"&amp;","<":"&lt;",">":"&gt;",'"':"&quot;","'":"&#39;"};return()=>{let e;function t(e){let t=(e.querySelector("[data-template]")||e.querySelector("script")||e).textContent;t=t.replace(new RegExp(N,"g"),"<\/script>");const n=t.match(/^\n?(\s*)/)[1].length,s=t.match(/^\n?(\t*)/)[1].length;return s>0?t=t.replace(new RegExp("\\n?\\t{"+s+"}(.*)","g"),(function(e,t){return"\n"+t})):n>1&&(t=t.replace(new RegExp("\\n? {"+n+"}(.*)","g"),(function(e,t){return"\n"+t}))),t}function n(e){const t=e.attributes,n=[];for(let e=0,s=t.length;e<s;e++){const s=t[e].name,r=t[e].value;/data\-(markdown|separator|vertical|notes)/gi.test(s)||(r?n.push(s+'="'+r+'"'):n.push(s))}return n.join(" ")}function s(t){const n=e.getConfig().markdown;return(t=t||{}).separator=t.separator||n?.separator||"\r?\n---\r?\n",t.verticalSeparator=t.verticalSeparator||n?.verticalSeparator||null,t.notesSeparator=t.notesSeparator||n?.notesSeparator||"^s*notes?:",t.attributes=t.attributes||"",t}function r(e,t){t=s(t);const n=e.split(new RegExp(t.notesSeparator,"mgi"));return 2===n.length&&(e=n[0]+'<aside class="notes">'+P(n[1].trim())+"</aside>"),'<script type="text/template">'+(e=e.replace(/<\/script>/g,N))+"<\/script>"}function i(e,t){t=s(t);const n=new RegExp(t.separator+(t.verticalSeparator?"|"+t.verticalSeparator:""),"mg"),i=new RegExp(t.separator);let l,o,a,c=0,h=!0,p=[];for(;l=n.exec(e);)o=i.test(l[0]),!o&&h&&p.push([]),a=e.substring(c,l.index),o&&h?p.push(a):p[p.length-1].push(a),c=n.lastIndex,h=o;(h?p:p[p.length-1]).push(e.substring(c));let u="";for(let e=0,n=p.length;e<n;e++)p[e]instanceof Array?(u+="<section "+t.attributes+">",p[e].forEach((function(e){u+="<section data-markdown>"+r(e,t)+"</section>"})),u+="</section>"):u+="<section "+t.attributes+" data-markdown>"+r(p[e],t)+"</section>";return u}function l(e){return new Promise((function(s){const r=[];[].slice.call(e.querySelectorAll("section[data-markdown]:not([data-markdown-parsed])")).forEach((function(e,s){e.getAttribute("data-markdown").length?r.push(function(e){return new Promise((function(t,n){const s=new XMLHttpRequest,r=e.getAttribute("data-markdown"),i=e.getAttribute("data-charset");null!==i&&""!==i&&s.overrideMimeType("text/html; charset="+i),s.onreadystatechange=function(e,s){4===s.readyState&&(s.status>=200&&s.status<300||0===s.status?t(s,r):n(s,r))}.bind(this,e,s),s.open("GET",r,!0);try{s.send()}catch(e){console.warn("Failed to get the Markdown file "+r+". Make sure that the presentation and the file are served by a HTTP server and the file can be found there. "+e),t(s,r)}}))}(e).then((function(t,s){e.outerHTML=i(t.responseText,{separator:e.getAttribute("data-separator"),verticalSeparator:e.getAttribute("data-separator-vertical"),notesSeparator:e.getAttribute("data-separator-notes"),attributes:n(e)})}),(function(t,n){e.outerHTML='<section data-state="alert">ERROR: The attempt to fetch '+n+" failed with HTTP status "+t.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>"}))):e.outerHTML=i(t(e),{separator:e.getAttribute("data-separator"),verticalSeparator:e.getAttribute("data-separator-vertical"),notesSeparator:e.getAttribute("data-separator-notes"),attributes:n(e)})})),Promise.all(r).then(s)}))}function o(e,t,n){const s=new RegExp(n,"mg"),r=new RegExp('([^"= ]+?)="([^"]+?)"|(data-[^"= ]+?)(?=[" ])',"mg");let i,l,o=e.nodeValue;if(i=s.exec(o)){const n=i[1];for(o=o.substring(0,i.index)+o.substring(s.lastIndex),e.nodeValue=o;l=r.exec(n);)l[2]?t.setAttribute(l[1],l[2]):t.setAttribute(l[3],"");return!0}return!1}function a(e,t,n,s,r){if(null!==t&&void 0!==t.childNodes&&t.childNodes.length>0){let n=t;for(let i=0;i<t.childNodes.length;i++){const l=t.childNodes[i];if(i>0){let e=i-1;for(;e>=0;){const s=t.childNodes[e];if("function"==typeof s.setAttribute&&"BR"!==s.tagName){n=s;break}e-=1}}let o=e;"section"===l.nodeName&&(o=l,n=l),"function"!=typeof l.setAttribute&&l.nodeType!==Node.COMMENT_NODE||a(o,l,n,s,r)}}t.nodeType===Node.COMMENT_N