markdown-it-multimd-table
Advanced tools
Comparing version 3.1.1 to 3.1.2
@@ -1,2 +0,2 @@ | ||
/*! markdown-it-multimd-table 3.1.1 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(){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}return e})()({1:[function(require,module,exports){ | ||
/*! markdown-it-multimd-table 3.1.2 https://github.com/RedBug312/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.markdownitMultimdTable = f()}})(function(){var define,module,exports;return (function(){function r(e,n,t){function o(i,f){if(!n[i]){if(!e[i]){var c="function"==typeof require&&require;if(!f&&c)return c(i,!0);if(u)return u(i,!0);var a=new Error("Cannot find module '"+i+"'");throw a.code="MODULE_NOT_FOUND",a}var p=n[i]={exports:{}};e[i][0].call(p.exports,function(r){var n=e[i][1][r];return o(n||r)},p,p.exports,r,e,n,t)}return n[i].exports}for(var u="function"==typeof require&&require,i=0;i<t.length;i++)o(t[i]);return o}return r})()({1:[function(require,module,exports){ | ||
'use strict'; | ||
@@ -334,2 +334,2 @@ | ||
},{}]},{},[1])(1) | ||
}); | ||
}); |
@@ -1,2 +0,2 @@ | ||
/*! markdown-it-multimd-table 3.1.1 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(){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 c=n[o]={exports:{}};t[o][0].call(c.exports,function(e){var n=t[o][1][e];return s(n||e)},c,c.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}return e}()({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,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 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 a(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 o(e,t,n,r){var s,a,o,l;s=t.split(/\n/).length,s>1?(a=e.md.block,o=new a.State(t,e.md,e.env,e.tokens),a.tokenize(o,0,s)):(l=e.push("inline","",0),l.content=t,l.map=[n,r],l.children=[])}function l(e,a,l,i,u,c){var p,f,h,d,b,g,m,x;if(p={colspans:null,columns:null,extractedTextLinesCount:1},f=r(a.replace(/^\||([^\\])\|$/g,"$1")),1===f.length&&!/^\||[^\\]\|$/.test(a))return!1;if(i)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,l+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(g=0;g<d.length;g++)f[g]=f[g].trim()+"\n"+d[g].trim();p.extractedTextLinesCount+=1}for(x=RegExp.prototype.test.bind(/[^\n]/),p.columns=f.filter(x),p.colspans=s(f.map(x)),b=e.push("tr_open","tr",1),b.map=[l,l+p.extractedTextLinesCount],g=0,m=0;g<p.columns.length&&m<u.aligns.length;m+=p.colspans[g],g++)b=e.push(c+"_open",c,1),b.map=[l,l+p.extractedTextLinesCount],b.attrs=[],u.aligns[m]&&b.attrs.push(["style","text-align:"+u.aligns[m]]),u.wraps[m]&&b.attrs.push(["class","extend"]),p.colspans[g]>1&&b.attrs.push(["colspan",p.colspans[g]]),o(e,p.columns[g].trim(),l,l+p.extractedTextLinesCount),b=e.push(c+"_close",c,-1);return e.push("tr_close","tr",-1),p}function i(e,t,n,s){var a,o,l,i;if(e.sCount[n]-e.blkIndent>=4)return!1;if(a=r(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 u(e,t,r,s){var o={65536:function(e,t,n){return a(e,n,t,!0)},4096:function(e,t,n){return i(e,n,t)},256:function(e,t,n){return l(e,n,t,!0,null,"th")},16:function(e,t,n){return l(e,n,t,!0,null,"td")},1:function(e,t,n){return!n}},u={65792:{65536:256,256:4352},256:{256:4352},4352:{4096:65552,256:4352},65552:{65536:0,16:65553},65553:{65536:0,16:65553,1:65552}};if(t+2>r)return!1;var c,p,f,h,d,b,g=!1;for(c=65792,p=t;c&&p<r;p++){for(d=n(e,p).trim(),f=65536;f>0&&!(c&f&&o[f].call(this,e,p,d));f>>=1);switch(f){case 65536:65792===c&&(g=!0);break;case 4096:if(b=i(e,d,p),s)return!0;break;case 256:case 16:case 1:break;case 0:if(256&c)return!1}c=u[c][f]||0}if(!b)return!1;var m,x,k,w;for(m=e.push("table_open","table",1),m.map=x=[t,0],c=65792,p=t;c&&p<r;p++){for(d=n(e,p).trim(),f=65536;f>0&&!(c&f&&o[f].call(this,e,p,d));f>>=1);switch(f){case 65536:65792!==c&&(w[1]=p,m=e.push("tbody_close","tbody",-1)),65792!==c&&g?p--:a(e,d,p,!1);break;case 4096:k[1]=p,m=e.push("thead_close","thead",-1);break;case 256:4352!==c&&(m=e.push("thead_open","thead",1),m.map=k=[p+1,0]),h=l(e,d,p,!1,b,"th"),p+=h.extractedTextLinesCount-1;break;case 16:65553!==c&&(m=e.push("tbody_open","tbody",1),m.map=w=[p+1,0]),h=l(e,d,p,!1,b,"td"),p+=h.extractedTextLinesCount-1;break;case 1:w[1]=p,m=e.push("tbody_close","tbody",-1);break;case 0:p--}c=u[c][f]||0}return w&&!w[1]&&(w[1]=p,m=e.push("tbody_close","tbody",-1)),x[1]=p,m=e.push("table_close","table",-1),e.line=p,!0}t=t||{},e.block.ruler.at("table",u,{alt:["paragraph","reference"]})}},{}]},{},[1])(1)}); | ||
/*! markdown-it-multimd-table 3.1.2 https://github.com/RedBug312/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.markdownitMultimdTable=e()}}(function(){return function(){function e(t,n,r){function s(o,l){if(!n[o]){if(!t[o]){var u="function"==typeof require&&require;if(!l&&u)return u(o,!0);if(a)return a(o,!0);var i=new Error("Cannot find module '"+o+"'");throw i.code="MODULE_NOT_FOUND",i}var c=n[o]={exports:{}};t[o][0].call(c.exports,function(e){return s(t[o][1][e]||e)},c,c.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}return e}()({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,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 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 a(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 o(e,t,n,r){var s,a,o,l;s=t.split(/\n/).length,s>1?(a=e.md.block,o=new a.State(t,e.md,e.env,e.tokens),a.tokenize(o,0,s)):(l=e.push("inline","",0),l.content=t,l.map=[n,r],l.children=[])}function l(e,a,l,u,i,c){var p,f,h,d,b,g,m,x;if(p={colspans:null,columns:null,extractedTextLinesCount:1},f=r(a.replace(/^\||([^\\])\|$/g,"$1")),1===f.length&&!/^\||[^\\]\|$/.test(a))return!1;if(u)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,l+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(g=0;g<d.length;g++)f[g]=f[g].trim()+"\n"+d[g].trim();p.extractedTextLinesCount+=1}for(x=RegExp.prototype.test.bind(/[^\n]/),p.columns=f.filter(x),p.colspans=s(f.map(x)),b=e.push("tr_open","tr",1),b.map=[l,l+p.extractedTextLinesCount],g=0,m=0;g<p.columns.length&&m<i.aligns.length;m+=p.colspans[g],g++)b=e.push(c+"_open",c,1),b.map=[l,l+p.extractedTextLinesCount],b.attrs=[],i.aligns[m]&&b.attrs.push(["style","text-align:"+i.aligns[m]]),i.wraps[m]&&b.attrs.push(["class","extend"]),p.colspans[g]>1&&b.attrs.push(["colspan",p.colspans[g]]),o(e,p.columns[g].trim(),l,l+p.extractedTextLinesCount),b=e.push(c+"_close",c,-1);return e.push("tr_close","tr",-1),p}function u(e,t,n,s){var a,o,l,u;if(e.sCount[n]-e.blkIndent>=4)return!1;if(a=r(t.replace(/^\||([^\\])\|$/g,"$1")),1===a.length&&!/^\||[^\\]\|$/.test(t))return!1;for(o={aligns:[],wraps:[]},l=0;l<a.length;l++){if(u=a[l].trim(),!/^:?(-+|=+):?\+?$/.test(u))return!1;switch(o.wraps.push(43===u.charCodeAt(u.length-1)),o.wraps[l]&&(u=u.slice(0,-1)),((58===u.charCodeAt(0))<<4)+(58===u.charCodeAt(u.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 i(e,t,r,s){var o={65536:function(e,t,n){return a(e,n,t,!0)},4096:function(e,t,n){return u(e,n,t)},256:function(e,t,n){return l(e,n,t,!0,null,"th")},16:function(e,t,n){return l(e,n,t,!0,null,"td")},1:function(e,t,n){return!n}},i={65792:{65536:256,256:4352},256:{256:4352},4352:{4096:65552,256:4352},65552:{65536:0,16:65553},65553:{65536:0,16:65553,1:65552}};if(t+2>r)return!1;var c,p,f,h,d,b,g=!1;for(c=65792,p=t;c&&p<r;p++){for(d=n(e,p).trim(),f=65536;f>0&&!(c&f&&o[f].call(this,e,p,d));f>>=1);switch(f){case 65536:65792===c&&(g=!0);break;case 4096:if(b=u(e,d,p),s)return!0;break;case 256:case 16:case 1:break;case 0:if(256&c)return!1}c=i[c][f]||0}if(!b)return!1;var m,x,k,w;for(m=e.push("table_open","table",1),m.map=x=[t,0],c=65792,p=t;c&&p<r;p++){for(d=n(e,p).trim(),f=65536;f>0&&!(c&f&&o[f].call(this,e,p,d));f>>=1);switch(f){case 65536:65792!==c&&(w[1]=p,m=e.push("tbody_close","tbody",-1)),65792!==c&&g?p--:a(e,d,p,!1);break;case 4096:k[1]=p,m=e.push("thead_close","thead",-1);break;case 256:4352!==c&&(m=e.push("thead_open","thead",1),m.map=k=[p+1,0]),h=l(e,d,p,!1,b,"th"),p+=h.extractedTextLinesCount-1;break;case 16:65553!==c&&(m=e.push("tbody_open","tbody",1),m.map=w=[p+1,0]),h=l(e,d,p,!1,b,"td"),p+=h.extractedTextLinesCount-1;break;case 1:w[1]=p,m=e.push("tbody_close","tbody",-1);break;case 0:p--}c=i[c][f]||0}return w&&!w[1]&&(w[1]=p,m=e.push("tbody_close","tbody",-1)),x[1]=p,m=e.push("table_close","table",-1),e.line=p,!0}t=t||{},e.block.ruler.at("table",i,{alt:["paragraph","reference"]})}},{}]},{},[1])(1)}); |
{ | ||
"name": "markdown-it-multimd-table", | ||
"version": "3.1.1", | ||
"version": "3.1.2", | ||
"description": "Multimarkdown table syntax plugin for markdown-it markdown parser", | ||
@@ -5,0 +5,0 @@ "keywords": [ |
@@ -5,16 +5,17 @@ [![NPM version](https://img.shields.io/npm/v/markdown-it-multimd-table.svg?style=flat)](https://www.npmjs.org/package/markdown-it-multimd-table) | ||
Multimarkdown table syntax plugin for markdown-it markdown parser | ||
MultiMarkdown table syntax plugin for markdown-it markdown parser | ||
## Intro | ||
Bored with HTML table tags when I need some extended table functions like `colspan` in Markdown. I found that [MultiMarkdown](https://fletcher.github.io/MultiMarkdown-6/) had defined complete and clear rules for advanced table syntax, which is compatible to standard Markdown table syntax at the same time. | ||
In general Markdown syntax, we have to write raw HTML tags when `colspan` attribute is needed. Luckily, I found that [MultiMarkdown](https://fletcher.github.io/MultiMarkdown-6/) had defined complete and clear rules for advanced Markdown table syntax, and compatible to general Markdown table syntax. | ||
For example, the following features are given: | ||
* `colspan` attribute | ||
* Multiple `<thead>` and `<tbody>` | ||
* Captions | ||
So I extend the table parser in markdown-it to support MultiMarkdown table syntax. For now, the following features are provided: | ||
- Cells spanning multiple columns | ||
- Grouped table headers | ||
- Grouped table rows | ||
- Table captions | ||
- Lists in table cell (optional) | ||
- Line breaks in table cells (optional) | ||
So I altered the table parser in markdown-it for the Multimarkdown syntax. | ||
Noted that the plugin might behave differently from MultiMarkdown in some edge cases; since the plugin was developed to follow the rules in [MultiMarkdown User's Guide](http://fletcher.github.io/MultiMarkdown-5/tables). | ||
NOTE: This plugin might behave differently from MultiMarkdown for some edging cases; For this plugin was developed mainly under the rules in [MultiMarkdown User's Guide](http://fletcher.github.io/MultiMarkdown-5/tables). Please impose an issue if you find problems related. | ||
## Usage | ||
@@ -28,21 +29,25 @@ ```javascript | ||
For test, do this in terminal: | ||
To simply test this plugin, you can do these in terminal: | ||
```javascript | ||
$ mkdir markdown-it-multimd-table | ||
$ cd markdown-it-multimd-table | ||
$ npm install markdown-it-multimd-table --prefix . | ||
$ vim test.js | ||
var md = require('markdown-it')() | ||
.use(require('markdown-it-multimd-table')); | ||
const exampleTable = | ||
"| | Grouping || \n" + | ||
"First Header | Second Header | Third Header | \n" + | ||
" ------------ | :-----------: | -----------: | \n" + | ||
"Content | *Long Cell* || \n" + | ||
"Content | **Cell** | Cell | \n" + | ||
" \n" + | ||
"New section | More | Data | \n" + | ||
"And more | With an escaped '\|' ||\n" + | ||
"[Prototype table] \n"; | ||
console.log(md.render(exampleTable)); | ||
var md = require('markdown-it')() | ||
.use(require('markdown-it-multimd-table')); | ||
const exampleTable = | ||
"| | Grouping || \n" + | ||
"First Header | Second Header | Third Header | \n" + | ||
" ------------ | :-----------: | -----------: | \n" + | ||
"Content | *Long Cell* || \n" + | ||
"Content | **Cell** | Cell | \n" + | ||
" \n" + | ||
"New section | More | Data | \n" + | ||
"And more | With an escaped '\\|' || \n" + | ||
"[Prototype table] \n"; | ||
console.log(md.render(exampleTable)); | ||
$ node test.js > test.html | ||
@@ -52,3 +57,3 @@ $ firefox test.html | ||
You might see the table in browser: | ||
And you will see the rendered table in the browser: | ||
@@ -92,5 +97,6 @@ <table> | ||
### Multiple lines of row | ||
### Multiple lines of row (optional) | ||
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). | ||
Put backslashes to indicate line-breaks to allow the table rows being parsed in multiple rows. | ||
This feature is contributed by [Lucas-C](https://github.com/Lucas-C). | ||
@@ -133,7 +139,7 @@ ```markdown | ||
To enable this feature, you have to set the option: | ||
Here's how you can enable the feature. | ||
```javascript | ||
var md = require('markdown-it')() | ||
.use(require('markdown-it-multimd-table'), {enableMultilineRows: true}); | ||
.use(require('markdown-it-multimd-table'), {enableMultilineRows: true}); | ||
``` | ||
@@ -143,5 +149,5 @@ | ||
* [MultiMarkdown](https://fletcher.github.io/MultiMarkdown-6/), Lightweight markup processor to produce HTML, LaTeX, and more. | ||
* [markdown-it](https://markdown-it.github.io/), Markdown parser, done right. 100% CommonMark support, extensions, syntax plugins & high speed | ||
* [markdown-it](https://markdown-it.github.io/), Markdown parser, done right. 100% CommonMark support, extensions, syntax plugins & high speed. | ||
## License | ||
This software is licensed under the [MIT license](https://opensource.org/licenses/mit-license.php) © RedBug312. |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
61171
641
148