forked from docsifyjs/docsify
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfront-matter.min.js
1 lines (1 loc) · 5.03 KB
/
front-matter.min.js
1
this.D=this.D||{},function(){"use strict";function e(e){return{parent:null,length:0,level:e,lines:[],children:[],addChild:function(e){this.children.push(e),e.parent=this,++this.length}}}function n(n){var t,r=g.regLevel,i=g.invalidLine,l=n.split("\n"),u=0,a=0,f=[],s=new e(-1),h=new e(0);s.addChild(h);var c=[],p="";f.push(h),c.push(u);for(var d=0,v=l.length;d<v;++d)if(p=l[d],!p.match(i)){if(u=(t=r.exec(p))?t[1].length:0,u>a){var m=h;h=new e(u),m.addChild(h),f.push(h),c.push(u)}else if(u<a){for(var w=!1,y=c.length-1;y>=0;--y)if(c[y]==u){h=new e(u),f.push(h),c.push(u),null!=f[y].parent&&f[y].parent.addChild(h),w=!0;break}if(!w)return void o.push("Error: Invalid indentation at line "+d+": "+p)}h.lines.push(p.replace(g.trim,"")),a=u}return s}function t(e){e=e.replace(g.trim,"");var n=null;if("true"==e)return!0;if("false"==e)return!1;if(".NaN"==e)return Number.NaN;if("null"==e)return null;if(".inf"==e)return Number.POSITIVE_INFINITY;if("-.inf"==e)return Number.NEGATIVE_INFINITY;if(n=e.match(g.dashesString))return n[1];if(n=e.match(g.quotesString))return n[1];if(n=e.match(g.float))return parseFloat(n[0]);if(n=e.match(g.integer))return parseInt(n[0]);if(isNaN(n=Date.parse(e))){if(n=e.match(g.single_key_value)){var r={};return r[n[1]]=t(n[2]),r}if(n=e.match(g.array)){for(var i=0,l=" ",r=[],u="",a=!1,f=0,s=n[1].length;f<s;++f){if(l=n[1][f],"'"==l||'"'==l){if(a===!1){a=l,u+=l;continue}if("'"==l&&"'"==a||'"'==l&&'"'==a){a=!1,u+=l;continue}}else if(a!==!1||"["!=l&&"{"!=l)if(a!==!1||"]"!=l&&"}"!=l){if(a===!1&&0==i&&","==l){r.push(t(u)),u="";continue}}else--i;else++i;u+=l}return u.length>0&&r.push(t(u)),r}if(n=e.match(g.map)){for(var i=0,l=" ",r=[],u="",a=!1,f=0,s=n[1].length;f<s;++f){if(l=n[1][f],"'"==l||'"'==l){if(a===!1){a=l,u+=l;continue}if("'"==l&&"'"==a||'"'==l&&'"'==a){a=!1,u+=l;continue}}else if(a!==!1||"["!=l&&"{"!=l)if(a!==!1||"]"!=l&&"}"!=l){if(a===!1&&0==i&&","==l){r.push(u),u="";continue}}else--i;else++i;u+=l}u.length>0&&r.push(u);for(var h={},f=0,s=r.length;f<s;++f)(n=r[f].match(g.key_value))&&(h[n[1]]=t(n[2]));return h}return e}return new Date(n)}function r(e){for(var n=e.lines,t=e.children,i=n.join(" "),l=[i],u=0,a=t.length;u<a;++u)l.push(r(t[u]));return l.join("\n")}function i(e){for(var n=e.lines,t=e.children,r=n.join("\n"),l=0,u=t.length;l<u;++l)r+=i(t[l]);return r}function l(e){for(var n=null,u={},a=null,f=null,s=null,h=-1,p=[],d=!0,v=0,m=e.length;v<m;++v)if(h==-1||h==e[v].level){p.push(v),h=e[v].level,a=e[v].lines,f=e[v].children,s=null;for(var w=0,y=a.length;w<y;++w){var E=a[w];if(n=E.match(g.key)){var x=n[1];if("-"==x[0]&&(x=x.replace(g.item,""),d&&(d=!1,"undefined"==typeof u.length&&(u=[])),null!=s&&u.push(s),s={},d=!0),"undefined"!=typeof n[2]){var b=n[2].replace(g.trim,"");if("&"==b[0]){var R=l(f);null!=s?s[x]=R:u[x]=R,c[b.substr(1)]=R}else if("|"==b[0])null!=s?s[x]=i(f.shift()):u[x]=i(f.shift());else if("*"==b[0]){var N=b.substr(1),_={};if("undefined"==typeof c[N])o.push("Reference '"+N+"' not found!");else{for(var $ in c[N])_[$]=c[N][$];null!=s?s[x]=_:u[x]=_}}else">"==b[0]?null!=s?s[x]=r(f.shift()):u[x]=r(f.shift()):null!=s?s[x]=t(b):u[x]=t(b)}else null!=s?s[x]=l(f):u[x]=l(f)}else{if(E.match(/^-\s*$/)){d&&(d=!1,"undefined"==typeof u.length&&(u=[])),null!=s&&u.push(s),s={},d=!0;continue}if(n=E.match(/^-\s*(.*)/)){null!=s?s.push(t(n[1])):(d&&(d=!1,"undefined"==typeof u.length&&(u=[])),u.push(t(n[1])));continue}}}null!=s&&(d&&(d=!1,"undefined"==typeof u.length&&(u=[])),u.push(s))}for(var v=p.length-1;v>=0;--v)e.splice.call(e,p[v],1);return u}function u(e){var n=l(e.children);return n}function a(e){var n,t=e.split("\n"),r=g.comment;for(var i in t)(n=t[i].match(r))&&"undefined"!=typeof n[3]&&(t[i]=n[0].substr(0,n[0].length-n[3].length));return t.join("\n")}function f(e){o=[],c=[],p=(new Date).getTime();var t=a(e),r=n(t),i=u(r);return p=(new Date).getTime()-p,i}function s(e){e=e||"";var n=e.split(/(\r?\n)/);return n[0]&&/= yaml =|---/.test(n[0])?h(e):{attributes:{},body:e}}function h(e){var n=m.exec(e);if(!n)return{attributes:{},body:e};var t=n[n.length-1].replace(/^\s+|\s+$/g,""),r=f(t)||{},i=e.replace(n[0],"");return{attributes:r,body:i,frontmatter:t}}var o=[],c=[],p=0,g={regLevel:new RegExp("^([\\s\\-]+)"),invalidLine:new RegExp("^\\-\\-\\-|^\\.\\.\\.|^\\s*#.*|^\\s*$"),dashesString:new RegExp('^\\s*\\"([^\\"]*)\\"\\s*$'),quotesString:new RegExp("^\\s*\\'([^\\']*)\\'\\s*$"),float:new RegExp("^[+-]?[0-9]+\\.[0-9]+(e[+-]?[0-9]+(\\.[0-9]+)?)?$"),integer:new RegExp("^[+-]?[0-9]+$"),array:new RegExp("\\[\\s*(.*)\\s*\\]"),map:new RegExp("\\{\\s*(.*)\\s*\\}"),key_value:new RegExp("([a-z0-9_-][ a-z0-9_-]*):( .+)","i"),single_key_value:new RegExp("^([a-z0-9_-][ a-z0-9_-]*):( .+?)$","i"),key:new RegExp("([a-z0-9_-][ a-z0-9_-]+):( .+)?","i"),item:new RegExp("^-\\s+"),trim:new RegExp("^\\s+|\\s+$"),comment:new RegExp("([^\\'\\\"#]+([\\'\\\"][^\\'\\\"]*[\\'\\\"])*)*(#.*)?")},d="\\ufeff?",v="^("+d+"(= yaml =|---)$([\\s\\S]*?)(?:\\2|\\.\\.\\.)$(?:\\n)?)",m=new RegExp(v,"m"),w=function(e,n){e.beforeEach(function(e){var t=s(e),r=t.attributes,i=t.body;return Docsify.util.merge(n.config,r.config),i})};window.$docsify.plugins=[].concat(w,window.$docsify.plugins)}();