const htmlEntities = require('html-entities'); const justify = require('justify-text'); module.exports = { max_column_width: 20, clean(str) { str = str.replace(/<\/?[^>]+(>|$)/g, ""); str = str.replace(/(\r\n|\n|\r)/gm, ""); str = htmlEntities.decode(str); return str; }, convert: function (table) { let result = "\n"; let caption = table.match(/]*>((?:.|\n)*)<\/caption>/i); if (caption) result += this.clean(caption[1]) + "\n\n"; let items = []; // collect data let rows = table.match(/(]*>(?:.|\n)*?<\/tr>)/gi); let n_rows = rows.length; for (let r=0;r]*>(?:.|\n)*?<\/t[h|d]>/gi); for (let c=0;c n_cols) { n_cols = items[r].length; } } // normalise columns for (let r=0;rcolumn_widths[c]) { if (l > this.max_column_width) { column_widths[c] = this.max_column_width; } else { column_widths[c] = l; } } } } // pad for (let r=0;r0 && n_cols > 0) { if (n_rows > 1) { result += "|"; for (let c=0;c