UNPKG

3.94 kBJavaScriptView Raw
1/*! markdown-it-multimd-table 3.0.0 https://github.com//markdown-it/markdown-it-multimd-table @license MIT */
2!function(e){if("object"==typeof exports&&"undefined"!=typeof module)module.exports=e();else if("function"==typeof define&&define.amd)define([],e);else{var t;t="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:this,t.markdownitDeflist=e()}}(function(){return function e(t,n,r){function s(o,l){if(!n[o]){if(!t[o]){var i="function"==typeof require&&require;if(!l&&i)return i(o,!0);if(a)return a(o,!0);var u=new Error("Cannot find module '"+o+"'");throw u.code="MODULE_NOT_FOUND",u}var p=n[o]={exports:{}};t[o][0].call(p.exports,function(e){var n=t[o][1][e];return s(n||e)},p,p.exports,e,t,n,r)}return n[o].exports}for(var a="function"==typeof require&&require,o=0;o<r.length;o++)s(r[o]);return s}({1:[function(e,t,n){"use strict";t.exports=function(e){function t(e,t){var n=e.bMarks[t]+e.blkIndent,r=e.eMarks[t];return e.src.slice(n,r)}function n(e){var t=[],n=0,r=e.length,s=0,a=!1,o=!1;for(n=0;n<r;n++)switch(e.charCodeAt(n)){case 92:a=!0;break;case 96:!o&&a||(o=!o),a=!1;break;case 124:o||a||(t.push(e.slice(s,n)),s=n+1),a=!1;break;default:a=!1}return t.push(e.slice(s)),t}function r(e){var t,n,r;for(n=0,r=[],t=e.length-1;t>=0;t--)e[t]?(r.unshift(n+1),n=0):n++;return n>0&&r.unshift(n+1),r}function s(e,t,n,r){var s,a,o;return!!(a=t.match(/^\[([^[\]]+)\](\[([^[\]]+)\])?\s*$/))&&(!!r||(s={caption:null,label:null},s.content=a[1],s.label=a[2]||a[1],o=e.push("caption_open","caption",1),o.map=[n,n+1],o.attrs=[["id",s.label.toLowerCase().replace(/\W+/g,"")]],o=e.push("inline","",0),o.content=s.content,o.map=[n,n+1],o.children=[],o=e.push("caption_close","caption",-1),s))}function a(e,t,s,a,o,l){var i,u,p,c,f;if(u=n(t.replace(/^\||([^\\])\|$/g,"$1")),1===u.length&&!/^\||[^\\]\|$/.test(t))return!1;if(a)return!0;for(i={colspans:null,columns:null},i.columns=u.filter(Boolean),i.colspans=r(u),p=e.push("tr_open","tr",1),p.map=[s,s+1],c=0,f=0;c<i.columns.length&&f<o.aligns.length;f+=i.colspans[c],c++)p=e.push(l+"_open",l,1),p.map=[s,s+1],p.attrs=[],o.aligns[f]&&p.attrs.push(["style","text-align:"+o.aligns[f]]),o.wraps[f]&&p.attrs.push(["class","extend"]),i.colspans[c]>1&&p.attrs.push(["colspan",i.colspans[c]]),p=e.push("inline","",0),p.content=i.columns[c].trim(),p.map=[s,s+1],p.children=[],p=e.push(l+"_close",l,-1);return p=e.push("tr_close","tr",-1),i}function o(e,t,r,s){var a,o,l,i;if(e.sCount[r]-e.blkIndent>=4)return!1;if(a=n(t.replace(/^\||([^\\])\|$/g,"$1")),1===a.length&&!/^\||[^\\]\|$/.test(t))return!1;for(o={aligns:[],wraps:[]},l=0;l<a.length;l++){if(i=a[l].trim(),!/^:?(-+|=+):?\+?$/.test(i))return!1;switch(o.wraps.push(43===i.charCodeAt(i.length-1)),o.wraps[l]&&(i=i.slice(0,-1)),((58===i.charCodeAt(0))<<4)+(58===i.charCodeAt(i.length-1))){case 0:o.aligns.push("");break;case 1:o.aligns.push("right");break;case 16:o.aligns.push("left");break;case 17:o.aligns.push("center")}}return s||o}function l(e,n,r,l){var i,u,p,c,f,h,d,b,g,m;if(n+2>r)return!1;if(u=p=!1,c=t(e,n).trim(),s(e,c,n,!0))u=!0;else if(!a(e,c,n,!0,null,"tr"))return!1;for(f=n+1;f<r;f++){if(c=t(e,f).trim(),o(e,c,f,!0)){i=f;break}if(!a(e,c,f,!0,null,"th"))return!1}if(!i)return!1;if(l)return!0;for(d=e.push("table_open","table",1),d.map=b=[n,0],h=o(e,c,i,!1),u&&(c=t(e,n).trim(),s(e,c,n,!1)),d=e.push("thead_open","thead",1),d.map=[n+u,i],f=n+u;f<i;f++)c=t(e,f).trim(),a(e,c,f,!1,h,"th");for(d=e.push("thead_close","thead",-1),d=e.push("tbody_open","tbody",1),d.map=g=[i+1,0],m=!0,f=i+1;f<r;f++){if(c=t(e,f).trim(),!u&&s(e,c,f,!0)){p=!0;break}if(a(e,c,f,!1,h,"td"))m=!1;else{if(m||c)break;g[1]=f-1,d=e.push("tbody_close","tbody",-1),d=e.push("tbody_open","tbody",1),d.map=g=[f+1,0],m=!0}}return d=e.push("tbody_close","tbody",-1),p&&(s(e,c,f,!1),f++),d=e.push("table_close","table",-1),b[1]=g[1]=f,e.line=f,!0}e.block.ruler.at("table",l,{alt:["paragraph","reference"]})}},{}]},{},[1])(1)});