Skip to content

Commit

Permalink
v1.0.5
Browse files Browse the repository at this point in the history
- Fix of issue #6
- Add `html-tr` class to TD and TH
- Add more tests for tables
  • Loading branch information
Aymkdn committed Aug 6, 2019
1 parent a6a5273 commit 227096e
Show file tree
Hide file tree
Showing 6 changed files with 521 additions and 125 deletions.
14 changes: 10 additions & 4 deletions docs/browser.js
Original file line number Diff line number Diff line change
Expand Up @@ -168,15 +168,18 @@ module.exports = function(htmlText, wndw) {
ret = {"_":ret, table:{body:[]}};
ret._.forEach(function(re) {
if (re.stack) {
var tr=[];
var td = []
re.stack.forEach(function(r) {
if (r.stack) {
ret.table.body.push(r.stack)
} else {
tr.push(r);
td.push(r);
}
});
if (tr.length>0) ret.table.body.push(tr);
if (td.length>0) ret.table.body.push(td);
} else {
// only one row
ret.table.body.push([re]);
}
});
delete ret._;
Expand Down Expand Up @@ -207,9 +210,12 @@ module.exports = function(htmlText, wndw) {
if (ret) {
if (Array.isArray(ret)) {
// add a custom class to let the user customize the element
if (ret.length === 1) {
// "tr" elements should always contain an array
if (ret.length === 1 && nodeName !== "tr") {
ret=ret[0];
ret.style = (ret.style||[]).concat(['html-'+nodeName]);
// for TD and TH we want to include the style from TR
if (nodeName === "td" || nodeName === "th") ret.style.push('html-tr');
} else {
ret = (nodeName==='p' ? {text:ret} : {stack:ret});
// we apply the default style if it's a "p"
Expand Down
Binary file modified example.pdf
Binary file not shown.
14 changes: 10 additions & 4 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -167,15 +167,18 @@ module.exports = function(htmlText, wndw) {
ret = {"_":ret, table:{body:[]}};
ret._.forEach(function(re) {
if (re.stack) {
var tr=[];
var td = []
re.stack.forEach(function(r) {
if (r.stack) {
ret.table.body.push(r.stack)
} else {
tr.push(r);
td.push(r);
}
});
if (tr.length>0) ret.table.body.push(tr);
if (td.length>0) ret.table.body.push(td);
} else {
// only one row
ret.table.body.push([re]);
}
});
delete ret._;
Expand Down Expand Up @@ -206,9 +209,12 @@ module.exports = function(htmlText, wndw) {
if (ret) {
if (Array.isArray(ret)) {
// add a custom class to let the user customize the element
if (ret.length === 1) {
// "tr" elements should always contain an array
if (ret.length === 1 && nodeName !== "tr") {
ret=ret[0];
ret.style = (ret.style||[]).concat(['html-'+nodeName]);
// for TD and TH we want to include the style from TR
if (nodeName === "td" || nodeName === "th") ret.style.push('html-tr');
} else {
ret = (nodeName==='p' ? {text:ret} : {stack:ret});
// we apply the default style if it's a "p"
Expand Down
Loading

0 comments on commit 227096e

Please sign in to comment.