const htmlEntities = require('html-entities'); const justify = require('justify-text'); module.exports = { max_width: 96, clean: function (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]) { column_widths[c] = l; } } } // decide how to present let total_width = 0; for (let c=0;c0 && n_cols > 0) { if (n_rows > 1) { result += "|"; for (let c=0;c