New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

markdown-it-multimd-table

Package Overview
Dependencies
Maintainers
1
Versions
26
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

markdown-it-multimd-table - npm Package Compare versions

Comparing version 3.0.0 to 3.1.0

test/fixtures/feature_multilines_row.txt

141

dist/markdown-it-multimd-table.js

@@ -1,5 +0,7 @@

/*! markdown-it-multimd-table 3.0.0 https://github.com//markdown-it/markdown-it-multimd-table @license MIT */(function(f){if(typeof exports==="object"&&typeof module!=="undefined"){module.exports=f()}else if(typeof define==="function"&&define.amd){define([],f)}else{var g;if(typeof window!=="undefined"){g=window}else if(typeof global!=="undefined"){g=global}else if(typeof self!=="undefined"){g=self}else{g=this}g.markdownitDeflist = f()}})(function(){var define,module,exports;return (function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(require,module,exports){
/*! markdown-it-multimd-table 3.1.0 https://github.com//markdown-it/markdown-it-multimd-table @license MIT */(function(f){if(typeof exports==="object"&&typeof module!=="undefined"){module.exports=f()}else if(typeof define==="function"&&define.amd){define([],f)}else{var g;if(typeof window!=="undefined"){g=window}else if(typeof global!=="undefined"){g=global}else if(typeof self!=="undefined"){g=self}else{g=this}g.markdownitDeflist = f()}})(function(){var define,module,exports;return (function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(require,module,exports){
'use strict';
module.exports = function multimd_table_plugin(md) {
module.exports = function multimd_table_plugin(md, pluginOptions) {
pluginOptions = pluginOptions || {};
function getLine(state, line) {

@@ -95,5 +97,23 @@ var pos = state.bMarks[line] + state.blkIndent,

function tableRow(state, lineText, lineNum, silent, seperatorInfo, rowType) {
var rowInfo, columns, token, i, col;
function appendRowToken(state, content, startLine, endLine) {
var linesCount, blockParser, tmpState, token;
linesCount = content.split(/\n/).length;
if (linesCount > 1) {
// Multiline content => subparsing as a block to support lists
blockParser = state.md.block;
tmpState = new blockParser.State(content, state.md, state.env, state.tokens);
blockParser.tokenize(tmpState, 0, linesCount); // appends to state.tokens
} else {
token = state.push('inline', '', 0);
token.content = content;
token.map = [ startLine, endLine ];
token.children = [];
}
}
function tableRow(state, lineText, lineNum, silent, separatorInfo, rowType) {
var rowInfo, columns, nextLineText, nextColumn, token, i, col, isValidColumn;
rowInfo = { colspans: null, columns: null, extractedTextLinesCount: 1 };
columns = escapedSplit(lineText.replace(/^\||([^\\])\|$/g, '$1'));

@@ -104,18 +124,30 @@ // lineText does not contain valid pipe character

rowInfo = { colspans: null, columns: null };
rowInfo.columns = columns.filter(Boolean);
rowInfo.colspans = countColspan(columns);
while (pluginOptions.enableMultilineRows && columns[columns.length - 1].slice(-1) === '\\') {
columns[columns.length - 1] = columns[columns.length - 1].slice(0, -1);
nextLineText = getLine(state, lineNum + rowInfo.extractedTextLinesCount);
nextColumn = escapedSplit(nextLineText.replace(/^\||([^\\])\|$/g, '$1'));
if (nextColumn.length === 1 && !/^\||[^\\]\|$/.test(nextLineText)) { return false; }
if (nextColumn.length !== columns.length && nextColumn.length !== columns.length - 1) { return false; }
for (i = 0; i < nextColumn.length; i++) {
columns[i] = columns[i].trim() + '\n' + nextColumn[i].trim();
}
rowInfo.extractedTextLinesCount += 1;
}
isValidColumn = RegExp.prototype.test.bind(/[^\n]/); // = (s => /[^\n]/.test(s))
rowInfo.columns = columns.filter(isValidColumn);
rowInfo.colspans = countColspan(columns.map(isValidColumn));
token = state.push('tr_open', 'tr', 1);
token.map = [ lineNum, lineNum + 1 ];
token.map = [ lineNum, lineNum + rowInfo.extractedTextLinesCount ];
for (i = 0, col = 0; i < rowInfo.columns.length && col < seperatorInfo.aligns.length;
for (i = 0, col = 0; i < rowInfo.columns.length && col < separatorInfo.aligns.length;
col += rowInfo.colspans[i], i++) {
token = state.push(rowType + '_open', rowType, 1);
token.map = [ lineNum, lineNum + 1 ];
token.map = [ lineNum, lineNum + rowInfo.extractedTextLinesCount ];
token.attrs = [];
if (seperatorInfo.aligns[col]) {
token.attrs.push([ 'style', 'text-align:' + seperatorInfo.aligns[col] ]);
if (separatorInfo.aligns[col]) {
token.attrs.push([ 'style', 'text-align:' + separatorInfo.aligns[col] ]);
}
if (seperatorInfo.wraps[col]) {
if (separatorInfo.wraps[col]) {
token.attrs.push([ 'class', 'extend' ]);

@@ -127,6 +159,3 @@ }

token = state.push('inline', '', 0);
token.content = rowInfo.columns[i].trim();
token.map = [ lineNum, lineNum + 1 ];
token.children = [];
appendRowToken(state, rowInfo.columns[i].trim(), lineNum, lineNum + rowInfo.extractedTextLinesCount);

@@ -136,3 +165,3 @@ token = state.push(rowType + '_close', rowType, -1);

token = state.push('tr_close', 'tr', -1);
state.push('tr_close', 'tr', -1);

@@ -142,4 +171,4 @@ return rowInfo;

function seperator(state, lineText, lineNum, silent) {
var columns, seperatorInfo, i, t;
function separator(state, lineText, lineNum, silent) {
var columns, separatorInfo, i, t;

@@ -153,3 +182,3 @@ // lineText have code indentation

seperatorInfo = { aligns: [], wraps: [] };
separatorInfo = { aligns: [], wraps: [] };

@@ -160,4 +189,4 @@ for (i = 0; i < columns.length; i++) {

seperatorInfo.wraps.push(t.charCodeAt(t.length - 1) === 0x2B/* + */);
if (seperatorInfo.wraps[i]) {
separatorInfo.wraps.push(t.charCodeAt(t.length - 1) === 0x2B/* + */);
if (separatorInfo.wraps[i]) {
t = t.slice(0, -1);

@@ -168,10 +197,10 @@ }

(t.charCodeAt(t.length - 1) === 0x3A/* : */)) {
case 0x00: seperatorInfo.aligns.push(''); break;
case 0x01: seperatorInfo.aligns.push('right'); break;
case 0x10: seperatorInfo.aligns.push('left'); break;
case 0x11: seperatorInfo.aligns.push('center'); break;
case 0x00: separatorInfo.aligns.push(''); break;
case 0x01: separatorInfo.aligns.push('right'); break;
case 0x10: separatorInfo.aligns.push('left'); break;
case 0x11: separatorInfo.aligns.push('center'); break;
}
}
return silent || seperatorInfo;
return silent || separatorInfo;
}

@@ -181,6 +210,6 @@

/* Regex pseudo code for table:
* caption? tableRow+ seperator (tableRow+ | empty)* caption?
* caption? tableRow+ separator (tableRow+ | empty)* caption?
*/
var seperatorLine, captionAtFirst, captionAtLast, lineText, nextLine,
seperatorInfo, token, tableLines, tbodyLines, emptyTBody;
var separatorLine, captionAtFirst, captionAtLast, lineText, nextLine,
rowInfo, separatorInfo, token, tableLines, tbodyLines, emptyTBody;

@@ -199,16 +228,14 @@ if (startLine + 2 > endLine) { return false; }

// second line ~ seperator line
// second line ~ separator line
for (nextLine = startLine + 1; nextLine < endLine; nextLine++) {
lineText = getLine(state, nextLine).trim();
if (seperator(state, lineText, nextLine, true)) {
seperatorLine = nextLine;
if (separator(state, lineText, nextLine, true)) {
separatorLine = nextLine;
break;
} else if (tableRow(state, lineText, nextLine, true, null, 'th')) {
continue;
} else {
} else if (!tableRow(state, lineText, nextLine, true, null, 'th')) {
return false;
}
}
if (!seperatorLine) { return false; }
if (!separatorLine) { return false; }
if (silent) { return true; }

@@ -219,3 +246,3 @@

seperatorInfo = seperator(state, lineText, seperatorLine, false);
separatorInfo = separator(state, lineText, separatorLine, false);

@@ -228,7 +255,9 @@ if (captionAtFirst) {

token = state.push('thead_open', 'thead', 1);
token.map = [ startLine + captionAtFirst, seperatorLine ];
token.map = [ startLine + captionAtFirst, separatorLine ];
for (nextLine = startLine + captionAtFirst; nextLine < seperatorLine; nextLine++) {
nextLine = startLine + captionAtFirst;
while (nextLine < separatorLine) {
lineText = getLine(state, nextLine).trim();
tableRow(state, lineText, nextLine, false, seperatorInfo, 'th');
rowInfo = tableRow(state, lineText, nextLine, false, separatorInfo, 'th');
nextLine += rowInfo.extractedTextLinesCount;
}

@@ -239,6 +268,7 @@

token = state.push('tbody_open', 'tbody', 1);
token.map = tbodyLines = [ seperatorLine + 1, 0 ];
token.map = tbodyLines = [ separatorLine + 1, 0 ];
emptyTBody = true;
for (nextLine = seperatorLine + 1; nextLine < endLine; nextLine++) {
nextLine = separatorLine + 1;
while (nextLine < endLine) {
lineText = getLine(state, nextLine).trim();

@@ -249,12 +279,17 @@

break;
} else if (tableRow(state, lineText, nextLine, false, seperatorInfo, 'td')) {
emptyTBody = false;
} else if (!emptyTBody && !lineText) {
tbodyLines[1] = nextLine - 1;
token = state.push('tbody_close', 'tbody', -1);
token = state.push('tbody_open', 'tbody', 1);
token.map = tbodyLines = [ nextLine + 1, 0 ];
emptyTBody = true;
} else {
break;
rowInfo = tableRow(state, lineText, nextLine, false, separatorInfo, 'td');
if (rowInfo) {
emptyTBody = false;
nextLine += rowInfo.extractedTextLinesCount;
} else if (!emptyTBody && !lineText) {
tbodyLines[1] = nextLine - 1;
token = state.push('tbody_close', 'tbody', -1);
token = state.push('tbody_open', 'tbody', 1);
token.map = tbodyLines = [ nextLine + 1, 0 ];
emptyTBody = true;
nextLine += 1;
} else {
break;
}
}

@@ -261,0 +296,0 @@ }

@@ -1,2 +0,2 @@

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

@@ -94,5 +96,23 @@ var pos = state.bMarks[line] + state.blkIndent,

function tableRow(state, lineText, lineNum, silent, seperatorInfo, rowType) {
var rowInfo, columns, token, i, col;
function appendRowToken(state, content, startLine, endLine) {
var linesCount, blockParser, tmpState, token;
linesCount = content.split(/\n/).length;
if (linesCount > 1) {
// Multiline content => subparsing as a block to support lists
blockParser = state.md.block;
tmpState = new blockParser.State(content, state.md, state.env, state.tokens);
blockParser.tokenize(tmpState, 0, linesCount); // appends to state.tokens
} else {
token = state.push('inline', '', 0);
token.content = content;
token.map = [ startLine, endLine ];
token.children = [];
}
}
function tableRow(state, lineText, lineNum, silent, separatorInfo, rowType) {
var rowInfo, columns, nextLineText, nextColumn, token, i, col, isValidColumn;
rowInfo = { colspans: null, columns: null, extractedTextLinesCount: 1 };
columns = escapedSplit(lineText.replace(/^\||([^\\])\|$/g, '$1'));

@@ -103,18 +123,30 @@ // lineText does not contain valid pipe character

rowInfo = { colspans: null, columns: null };
rowInfo.columns = columns.filter(Boolean);
rowInfo.colspans = countColspan(columns);
while (pluginOptions.enableMultilineRows && columns[columns.length - 1].slice(-1) === '\\') {
columns[columns.length - 1] = columns[columns.length - 1].slice(0, -1);
nextLineText = getLine(state, lineNum + rowInfo.extractedTextLinesCount);
nextColumn = escapedSplit(nextLineText.replace(/^\||([^\\])\|$/g, '$1'));
if (nextColumn.length === 1 && !/^\||[^\\]\|$/.test(nextLineText)) { return false; }
if (nextColumn.length !== columns.length && nextColumn.length !== columns.length - 1) { return false; }
for (i = 0; i < nextColumn.length; i++) {
columns[i] = columns[i].trim() + '\n' + nextColumn[i].trim();
}
rowInfo.extractedTextLinesCount += 1;
}
isValidColumn = RegExp.prototype.test.bind(/[^\n]/); // = (s => /[^\n]/.test(s))
rowInfo.columns = columns.filter(isValidColumn);
rowInfo.colspans = countColspan(columns.map(isValidColumn));
token = state.push('tr_open', 'tr', 1);
token.map = [ lineNum, lineNum + 1 ];
token.map = [ lineNum, lineNum + rowInfo.extractedTextLinesCount ];
for (i = 0, col = 0; i < rowInfo.columns.length && col < seperatorInfo.aligns.length;
for (i = 0, col = 0; i < rowInfo.columns.length && col < separatorInfo.aligns.length;
col += rowInfo.colspans[i], i++) {
token = state.push(rowType + '_open', rowType, 1);
token.map = [ lineNum, lineNum + 1 ];
token.map = [ lineNum, lineNum + rowInfo.extractedTextLinesCount ];
token.attrs = [];
if (seperatorInfo.aligns[col]) {
token.attrs.push([ 'style', 'text-align:' + seperatorInfo.aligns[col] ]);
if (separatorInfo.aligns[col]) {
token.attrs.push([ 'style', 'text-align:' + separatorInfo.aligns[col] ]);
}
if (seperatorInfo.wraps[col]) {
if (separatorInfo.wraps[col]) {
token.attrs.push([ 'class', 'extend' ]);

@@ -126,6 +158,3 @@ }

token = state.push('inline', '', 0);
token.content = rowInfo.columns[i].trim();
token.map = [ lineNum, lineNum + 1 ];
token.children = [];
appendRowToken(state, rowInfo.columns[i].trim(), lineNum, lineNum + rowInfo.extractedTextLinesCount);

@@ -135,3 +164,3 @@ token = state.push(rowType + '_close', rowType, -1);

token = state.push('tr_close', 'tr', -1);
state.push('tr_close', 'tr', -1);

@@ -141,4 +170,4 @@ return rowInfo;

function seperator(state, lineText, lineNum, silent) {
var columns, seperatorInfo, i, t;
function separator(state, lineText, lineNum, silent) {
var columns, separatorInfo, i, t;

@@ -152,3 +181,3 @@ // lineText have code indentation

seperatorInfo = { aligns: [], wraps: [] };
separatorInfo = { aligns: [], wraps: [] };

@@ -159,4 +188,4 @@ for (i = 0; i < columns.length; i++) {

seperatorInfo.wraps.push(t.charCodeAt(t.length - 1) === 0x2B/* + */);
if (seperatorInfo.wraps[i]) {
separatorInfo.wraps.push(t.charCodeAt(t.length - 1) === 0x2B/* + */);
if (separatorInfo.wraps[i]) {
t = t.slice(0, -1);

@@ -167,10 +196,10 @@ }

(t.charCodeAt(t.length - 1) === 0x3A/* : */)) {
case 0x00: seperatorInfo.aligns.push(''); break;
case 0x01: seperatorInfo.aligns.push('right'); break;
case 0x10: seperatorInfo.aligns.push('left'); break;
case 0x11: seperatorInfo.aligns.push('center'); break;
case 0x00: separatorInfo.aligns.push(''); break;
case 0x01: separatorInfo.aligns.push('right'); break;
case 0x10: separatorInfo.aligns.push('left'); break;
case 0x11: separatorInfo.aligns.push('center'); break;
}
}
return silent || seperatorInfo;
return silent || separatorInfo;
}

@@ -180,6 +209,6 @@

/* Regex pseudo code for table:
* caption? tableRow+ seperator (tableRow+ | empty)* caption?
* caption? tableRow+ separator (tableRow+ | empty)* caption?
*/
var seperatorLine, captionAtFirst, captionAtLast, lineText, nextLine,
seperatorInfo, token, tableLines, tbodyLines, emptyTBody;
var separatorLine, captionAtFirst, captionAtLast, lineText, nextLine,
rowInfo, separatorInfo, token, tableLines, tbodyLines, emptyTBody;

@@ -198,16 +227,14 @@ if (startLine + 2 > endLine) { return false; }

// second line ~ seperator line
// second line ~ separator line
for (nextLine = startLine + 1; nextLine < endLine; nextLine++) {
lineText = getLine(state, nextLine).trim();
if (seperator(state, lineText, nextLine, true)) {
seperatorLine = nextLine;
if (separator(state, lineText, nextLine, true)) {
separatorLine = nextLine;
break;
} else if (tableRow(state, lineText, nextLine, true, null, 'th')) {
continue;
} else {
} else if (!tableRow(state, lineText, nextLine, true, null, 'th')) {
return false;
}
}
if (!seperatorLine) { return false; }
if (!separatorLine) { return false; }
if (silent) { return true; }

@@ -218,3 +245,3 @@

seperatorInfo = seperator(state, lineText, seperatorLine, false);
separatorInfo = separator(state, lineText, separatorLine, false);

@@ -227,7 +254,9 @@ if (captionAtFirst) {

token = state.push('thead_open', 'thead', 1);
token.map = [ startLine + captionAtFirst, seperatorLine ];
token.map = [ startLine + captionAtFirst, separatorLine ];
for (nextLine = startLine + captionAtFirst; nextLine < seperatorLine; nextLine++) {
nextLine = startLine + captionAtFirst;
while (nextLine < separatorLine) {
lineText = getLine(state, nextLine).trim();
tableRow(state, lineText, nextLine, false, seperatorInfo, 'th');
rowInfo = tableRow(state, lineText, nextLine, false, separatorInfo, 'th');
nextLine += rowInfo.extractedTextLinesCount;
}

@@ -238,6 +267,7 @@

token = state.push('tbody_open', 'tbody', 1);
token.map = tbodyLines = [ seperatorLine + 1, 0 ];
token.map = tbodyLines = [ separatorLine + 1, 0 ];
emptyTBody = true;
for (nextLine = seperatorLine + 1; nextLine < endLine; nextLine++) {
nextLine = separatorLine + 1;
while (nextLine < endLine) {
lineText = getLine(state, nextLine).trim();

@@ -248,12 +278,17 @@

break;
} else if (tableRow(state, lineText, nextLine, false, seperatorInfo, 'td')) {
emptyTBody = false;
} else if (!emptyTBody && !lineText) {
tbodyLines[1] = nextLine - 1;
token = state.push('tbody_close', 'tbody', -1);
token = state.push('tbody_open', 'tbody', 1);
token.map = tbodyLines = [ nextLine + 1, 0 ];
emptyTBody = true;
} else {
break;
rowInfo = tableRow(state, lineText, nextLine, false, separatorInfo, 'td');
if (rowInfo) {
emptyTBody = false;
nextLine += rowInfo.extractedTextLinesCount;
} else if (!emptyTBody && !lineText) {
tbodyLines[1] = nextLine - 1;
token = state.push('tbody_close', 'tbody', -1);
token = state.push('tbody_open', 'tbody', 1);
token.map = tbodyLines = [ nextLine + 1, 0 ];
emptyTBody = true;
nextLine += 1;
} else {
break;
}
}

@@ -260,0 +295,0 @@ }

{
"name": "markdown-it-multimd-table",
"version": "3.0.0",
"version": "3.1.0",
"description": "Multimarkdown table syntax plugin for markdown-it markdown parser",

@@ -5,0 +5,0 @@ "keywords": [

@@ -28,3 +28,3 @@ [![NPM version](https://img.shields.io/npm/v/markdown-it-multimd-table.svg?style=flat)](https://www.npmjs.org/package/markdown-it-multimd-table)

For test, do this in terminal:
```bash
```javascript
$ npm install markdown-it-multimd-table --prefix .

@@ -43,3 +43,3 @@ $ vim test.js

"New section | More | Data | \n" +
"And more | With an escaped '\\|' ||\n" +
"And more | With an escaped '\|' ||\n" +
"[Prototype table] \n";

@@ -52,2 +52,88 @@ console.log(md.render(exampleTable));

You might see the table in browser:
<table>
<thead>
<tr>
<th></th>
<th style="text-align:center" colspan="2">Grouping</th>
</tr>
<tr>
<th>First Header</th>
<th style="text-align:center">Second Header</th>
<th style="text-align:right">Third Header</th>
</tr>
</thead>
<tbody>
<tr>
<td>Content</td>
<td style="text-align:center" colspan="2"><em>Long Cell</em></td>
</tr>
<tr>
<td>Content</td>
<td style="text-align:center"><strong>Cell</strong></td>
<td style="text-align:right">Cell</td>
</tr>
</tbody>
<tbody>
<tr>
<td>New section</td>
<td style="text-align:center">More</td>
<td style="text-align:right">Data</td>
</tr>
<tr>
<td>And more</td>
<td style="text-align:center" colspan="2">With an escaped '|'</td>
</tr>
</tbody>
<caption id="prototypetable">Prototype table</caption>
</table>
### Multiple lines of row
Allow table rows parsed as multiple lines with end-of-the-line backslashes, the feature is contributed by [Lucas-C](https://github.com/Lucas-C).
```markdown
First header | Second header
-------------|---------------
List: | More \
- over | data \
- several | \
- lines |
```
would be parsed as
<table>
<thead>
<tr>
<th>First header</th>
<th>Second header</th>
</tr>
</thead>
<tbody>
<tr>
<td>
<p>List:</p>
<ul>
<li>over</li>
<li>several</li>
<li>lines</li>
</ul>
</td>
<td>
<p>More
data</p>
</td>
</tr>
</tbody>
</table>
To enable this feature, you have to set the option:
```javascript
var md = require('markdown-it')()
.use(require('markdown-it-multimd-table'), {enableMultilineRows: true});
```
## Credits

@@ -54,0 +140,0 @@ * [MultiMarkdown](https://fletcher.github.io/MultiMarkdown-6/), Lightweight markup processor to produce HTML, LaTeX, and more.

@@ -35,1 +35,8 @@ 'use strict';

});
describe('Support rows defined on several lines', function () {
var md = require('markdown-it')()
.use(require('../'), { enableMultilineRows: true });
generate(path.join(__dirname, 'fixtures/feature_multilines_row.txt'), md);
});

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc