/*global module:true*/ /* * Basic table support with re-entrant parsing, where cell content * can also specify markdown. * * Tables * ====== * * | Col 1 | Col 2 | * |======== |====================================================| * |**bold** | ![Valid XHTML] (http://w3.org/Icons/valid-xhtml10) | * | Plain | Value | * */ (function(){ var table = function(converter) { var tables = {}, style = 'text-align:left;', filter; tables.th = function(header){ if (header.trim() === "") { return "";} var id = header.trim().replace(/ /g, '_').toLowerCase(); return '' + header + ''; }; tables.td = function(cell) { return '' + converter.makeHtml(cell) + ''; }; tables.ths = function(){ var out = "", i = 0, hs = [].slice.apply(arguments); for (i;i'); hs = line.substring(1, line.length -1).split('|'); tbl.push(tables.thead.apply(this, hs)); line = lines[++i]; if (!line.trim().match(/^[|]{1}[-=| ]+[|]{1}$/)) { // not a table rolling back line = lines[--i]; } else { line = lines[++i]; tbl.push(''); while (line.trim().match(/^[|]{1}.*[|]{1}$/)) { line = line.trim(); tbl.push(tables.tr.apply(this, line.substring(1, line.length -1).split('|'))); line = lines[++i]; } tbl.push(''); tbl.push(''); // we are done with this table and we move along out.push(tbl.join('\n')); tbl = []; continue; } } out.push(line); } return out.join('\n'); }; return [ { type: 'lang', filter: filter } ]; }; // Client-side export if (typeof window !== 'undefined' && window.Showdown && window.Showdown.extensions) { window.Showdown.extensions.table = table; } // Server-side export if (typeof module !== 'undefined') { module.exports = table; } }());