const htmlEntities = require('html-entities');
module.exports = {
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]) {
column_widths[c]=l;
}
}
}
for (let r=0;r0 && n_cols > 0) {
if (n_rows > 1) {
result += "|";
for (let c=0;c