html-to-text
Advanced tools
Comparing version 1.0.0 to 1.1.0
@@ -130,34 +130,44 @@ var _ = require('underscore'); | ||
var table = []; | ||
_.each(elem.children, function(elem) { | ||
if (elem.type === 'tag' && elem.name === 'tr') { | ||
var rows = []; | ||
_.each(elem.children, function(elem) { | ||
var tokens, times; | ||
if (elem.type === 'tag') { | ||
if (elem.name === 'th') { | ||
tokens = formatHeading(elem, fn, options).split('\n'); | ||
rows.push(_.compact(tokens)); | ||
} else if (elem.name === 'td') { | ||
tokens = fn(elem.children, options).split('\n'); | ||
rows.push(_.compact(tokens)); | ||
// Fill colspans with empty values | ||
if (elem.attribs && elem.attribs.colspan) { | ||
times = elem.attribs.colspan - 1; | ||
_.times(times, function() { | ||
rows.push(['']); | ||
}); | ||
} | ||
_.each(elem.children, tryParseRows); | ||
return tableToString(table); | ||
function tryParseRows(elem) { | ||
if (elem.type !== 'tag') { | ||
return; | ||
} | ||
if (elem.name === "thead" || elem.name === "tbody" || elem.name === "tfoot") { | ||
_.each(elem.children, tryParseRows); | ||
return; | ||
} | ||
if (elem.name !== 'tr') { | ||
return; | ||
} | ||
var rows = []; | ||
_.each(elem.children, function(elem) { | ||
var tokens, times; | ||
if (elem.type === 'tag') { | ||
if (elem.name === 'th') { | ||
tokens = formatHeading(elem, fn, options).split('\n'); | ||
rows.push(_.compact(tokens)); | ||
} else if (elem.name === 'td') { | ||
tokens = fn(elem.children, options).split('\n'); | ||
rows.push(_.compact(tokens)); | ||
// Fill colspans with empty values | ||
if (elem.attribs && elem.attribs.colspan) { | ||
times = elem.attribs.colspan - 1; | ||
_.times(times, function() { | ||
rows.push(['']); | ||
}); | ||
} | ||
} | ||
} | ||
}); | ||
rows = helper.arrayZip(rows); | ||
_.each(rows, function(row) { | ||
row = _.map(row, function(col) { | ||
return col || ''; | ||
}); | ||
rows = helper.arrayZip(rows); | ||
_.each(rows, function(row) { | ||
row = _.map(row, function(col) { | ||
return col || ''; | ||
}); | ||
table.push(row); | ||
}); | ||
} | ||
}); | ||
return tableToString(table); | ||
table.push(row); | ||
}); | ||
} | ||
} | ||
@@ -164,0 +174,0 @@ |
{ | ||
"name": "html-to-text", | ||
"version": "1.0.0", | ||
"version": "1.1.0", | ||
"description": "Advanced html to plain text converter", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -100,38 +100,44 @@ # node-html-to-text | ||
<table id="invoice"> | ||
<tr> | ||
<th>Article</th> | ||
<th>Price</th> | ||
<th>Taxes</th> | ||
<th>Amount</th> | ||
<th>Total</th> | ||
</tr> | ||
<tr> | ||
<td> | ||
<p> | ||
Product 1<br /> | ||
<span style="font-size:0.8em">Contains: 1x Product 1</span> | ||
</p> | ||
</td> | ||
<td align="right" valign="top">6,99€</td> | ||
<td align="right" valign="top">7%</td> | ||
<td align="right" valign="top">1</td> | ||
<td align="right" valign="top">6,99€</td> | ||
</tr> | ||
<tr> | ||
<td>Shipment costs</td> | ||
<td align="right">3,25€</td> | ||
<td align="right">7%</td> | ||
<td align="right">1</td> | ||
<td align="right">3,25€</td> | ||
</tr> | ||
<tr> | ||
<td> </td> | ||
<td> </td> | ||
<td colspan="3">to pay: 10,24€</td> | ||
</tr> | ||
<tr> | ||
<td></td> | ||
<td></td> | ||
<td colspan="3">Taxes 7%: 0,72€</td> | ||
</tr> | ||
<thead> | ||
<tr> | ||
<th>Article</th> | ||
<th>Price</th> | ||
<th>Taxes</th> | ||
<th>Amount</th> | ||
<th>Total</th> | ||
</tr> | ||
</thead> | ||
<tbody> | ||
<tr> | ||
<td> | ||
<p> | ||
Product 1<br /> | ||
<span style="font-size:0.8em">Contains: 1x Product 1</span> | ||
</p> | ||
</td> | ||
<td align="right" valign="top">6,99€</td> | ||
<td align="right" valign="top">7%</td> | ||
<td align="right" valign="top">1</td> | ||
<td align="right" valign="top">6,99€</td> | ||
</tr> | ||
<tr> | ||
<td>Shipment costs</td> | ||
<td align="right">3,25€</td> | ||
<td align="right">7%</td> | ||
<td align="right">1</td> | ||
<td align="right">3,25€</td> | ||
</tr> | ||
</tbody> | ||
<tfoot> | ||
<tr> | ||
<td> </td> | ||
<td> </td> | ||
<td colspan="3">to pay: 10,24€</td> | ||
</tr> | ||
<tr> | ||
<td></td> | ||
<td></td> | ||
<td colspan="3">Taxes 7%: 0,72€</td> | ||
</tr> | ||
</tfoot> | ||
</table> | ||
@@ -138,0 +144,0 @@ |
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
30997
411
294