From 215af85f4bd15ab38f27c0d4689b870290b3012c Mon Sep 17 00:00:00 2001 From: Aymeric Date: Fri, 8 May 2020 10:23:02 +0200 Subject: [PATCH] v1.2.5 Fixed https://github.com/Aymkdn/html-to-pdfmake/issues/46 --- docs/browser.js | 2 +- example.pdf | Bin 37161 -> 37161 bytes index.js | 37 +++++++++++++++++++++++++++++++------ package.json | 2 +- test/unit.js | 44 +++++++++++++++++++++++++------------------- 5 files changed, 58 insertions(+), 27 deletions(-) diff --git a/docs/browser.js b/docs/browser.js index cadd53c..7b567ff 100644 --- a/docs/browser.js +++ b/docs/browser.js @@ -1 +1 @@ -(function(f){if(typeof exports==="object"&&typeof module!=="undefined"){module.exports=f()}else if(typeof define==="function"&&define.amd){define([],f)}else{var g;if(typeof window!=="undefined"){g=window}else if(typeof global!=="undefined"){g=global}else if(typeof self!=="undefined"){g=self}else{g=this}g.htmlToPdfmake=f()}})(function(){var define,module,exports;return function(){function r(e,n,t){function o(i,f){if(!n[i]){if(!e[i]){var c="function"==typeof require&&require;if(!f&&c)return c(i,!0);if(u)return u(i,!0);var a=new Error("Cannot find module '"+i+"'");throw a.code="MODULE_NOT_FOUND",a}var p=n[i]={exports:{}};e[i][0].call(p.exports,function(r){var n=e[i][1][r];return o(n||r)},p,p.exports,r,e,n,t)}return n[i].exports}for(var u="function"==typeof require&&require,i=0;i-1)return ret;ret={text:text};if(parentNodeName){applyParentsStyle(ret,element);if(parentNodeName==="a"){ret.link=parentNode.getAttribute("href")}}else{ret=text}}}return ret}case 1:{ret=[];parents.push(nodeName);if(element.childNodes.length===0&&(parents.indexOf("th")>-1||parents.indexOf("td")>-1)){var ancestor=element;var allEmpty=true;while(ancestor.nodeName!=="TH"&&ancestor.nodeName!=="TD"){if(ancestor.textContent!==""){allEmpty=false;break}ancestor=ancestor.parentNode}if(allEmpty)ret.push({text:""})}else{[].forEach.call(element.childNodes,function(child){child=parseElement(child,element,parents);if(child){if(Array.isArray(child)&&child.length===1)child=child[0];ret.push(child)}});parents.pop()}if(ret.length===0)ret="";switch(nodeName){case"svg":{ret={svg:element.outerHTML};ret.style=["html-"+nodeName];break}case"br":{ret="\n";break}case"hr":{var styleHR={width:514,type:"line",margin:[0,12,0,12],thickness:.5,color:"#000000",left:0};if(element.dataset&&element.dataset.pdfmake){dataset=JSON.parse(element.dataset.pdfmake);for(key in dataset){styleHR[key]=dataset[key]}}ret={margin:styleHR.margin,canvas:[{type:styleHR.type,x1:styleHR.left,y1:0,x2:styleHR.width,y2:0,lineWidth:styleHR.thickness,lineColor:styleHR.color}]};break}case"ol":case"ul":{ret={_:ret};ret[nodeName]=ret._;delete ret._;ret.style=["html-"+nodeName];cssClass=element.getAttribute("class");if(cssClass){ret.style=ret.style.concat(cssClass.split(" "))}setComputedStyle(ret,element.getAttribute("style"));break}case"table":{ret={_:ret,table:{body:[]}};ret._.forEach(function(re){if(re.stack){var td=[],rowspan={};re.stack.forEach(function(r,indexRow){var c,cell,i,indexCell;if(r.stack){if(rowspan[indexRow]){rowspan[indexRow].forEach(function(cell){r.stack.splice(cell.index,0,{text:"",style:["html-td","html-tr"],colSpan:cell.colspan})})}for(c=0,cell;c1){for(i=0;i1){for(i=0;i0)ret.table.body.push(td)}else{ret.table.body.push([re])}});delete ret._;setComputedStyle(ret,element.getAttribute("style"));break}case"img":{ret={image:element.getAttribute("src")};ret.style=["html-img"];cssClass=element.getAttribute("class");if(cssClass){ret.style=ret.style.concat(cssClass.split(" "))}if(element.getAttribute("width")){ret.width=parseFloat(element.getAttribute("width"))}if(element.getAttribute("height")){ret.height=parseFloat(element.getAttribute("height"))}setComputedStyle(ret,element.getAttribute("style"));break}}if(ret){if(Array.isArray(ret)){if(ret.length===1&&nodeName!=="tr"){ret=ret[0];if(typeof ret==="string")ret={text:ret};if(ret.text){applyDefaultStyle(ret,nodeName);setComputedStyle(ret,element.getAttribute("style"))}ret.style=(ret.style||[]).concat(["html-"+nodeName]);if(nodeName==="td"||nodeName==="th")ret.style.push("html-tr")}else{isInlineTag=inlineTags.indexOf(nodeName)>-1;ret=!isInlineTag||/{"(stack|table|ol|ul|image)"/.test(JSON.stringify(ret))?{stack:ret}:{text:ret};if(isInlineTag){applyDefaultStyle(ret,nodeName)}ret.style=["html-"+nodeName]}applyParentsStyle(ret,element);if(nodeName==="td"||nodeName==="th"){if(element.getAttribute("rowspan"))ret.rowSpan=element.getAttribute("rowspan")*1;if(element.getAttribute("colspan"))ret.colSpan=element.getAttribute("colspan")*1}cssClass=element.getAttribute("class");if(cssClass){ret.style=(ret.style||[]).concat(cssClass.split(" "))}if(ret.text){setComputedStyle(ret,element.getAttribute("style"))}}else if(ret.table||ret.ol||ret.ul){ret.style=["html-"+nodeName];cssClass=element.getAttribute("class");if(cssClass){ret.style=ret.style.concat(cssClass.split(" "))}applyDefaultStyle(ret,nodeName)}if(element.dataset&&element.dataset.pdfmake){dataset=JSON.parse(element.dataset.pdfmake);dist=ret[nodeName]||ret;for(key in dataset){dist[key]=dataset[key]}}cssClass=element.getAttribute("class");if(cssClass&&typeof ret==="object"){ret.style=(ret.style||[]).concat(cssClass.split(" "))}if(typeof ret==="object"&&Array.isArray(ret.style)){ret.style=ret.style.filter(function(value,index,self){return self.indexOf(value)===index})}}return ret}}return""};var applyDefaultStyle=function(ret,nodeName){if(defaultStyles[nodeName]){for(var style in defaultStyles[nodeName]){if(defaultStyles[nodeName].hasOwnProperty(style)){ret[style]=defaultStyles[nodeName][style]}}}};var applyParentsStyle=function(ret,node){var classes=[],defaultStyles=[],cssClass;var inlineParentNode=node.parentNode;while(inlineParentNode){var defaultStyle={};var inlineParentNodeName=inlineParentNode.nodeName.toLowerCase();if(inlineTags.indexOf(inlineParentNodeName)>-1){cssClass=inlineParentNode.getAttribute("class");classes=classes.concat(["html-"+inlineParentNodeName],cssClass||[]);applyDefaultStyle(defaultStyle,inlineParentNodeName);defaultStyles.push(defaultStyle);inlineParentNode=inlineParentNode.parentNode}else break}ret.style=(ret.style||[]).concat(classes);defaultStyles.forEach(function(defaultStyle){for(var key in defaultStyle){if(key.indexOf("margin")===-1&&ret[key]===undefined)ret[key]=defaultStyle[key]}})};var computeStyle=function(style){var styleDefs=style.split(";").map(function(style){return style.replace(/\s/g,"").toLowerCase().split(":")});var ret=[];styleDefs.forEach(function(styleDef){var key=styleDef[0];var value=styleDef[1];switch(key){case"margin":{value=value.replace(/(\d+)(\.\d+)?([^\d]+)/g,"$1$2 ").trim().split(" ");if(value.length===1)value=+value[0];else if(value.length===2)value=[+value[1],+value[0]];else if(value.length===3)value=[+value[1],+value[0],+value[1],+value[2]];else if(value.length===4)value=[+value[3],+value[0],+value[1],+value[2]];ret.push({key:key,value:value});break}case"text-align":{ret.push({key:"alignment",value:value});break}case"font-weight":{if(value==="bold")ret.push({key:"bold",value:true});break}case"text-decoration":{ret.push({key:"decoration",value:toCamelCase(value)});break}case"font-style":{if(value==="italic")ret.push({key:"italics",value:true});break}case"color":{ret.push({key:"color",value:parseColor(value)});break}case"background-color":{ret.push({key:"background",value:parseColor(value)});break}default:{if(key.indexOf("-")>-1)key=toCamelCase(key);if(value){value=value.replace(/(\d+)(\.\d+)?([^\d]+)/g,"$1$2 ").trim();if(!isNaN(value))value=+value;ret.push({key:key,value:value})}}}});return ret};var setComputedStyle=function(ret,cssStyle){if(cssStyle){cssStyle=computeStyle(cssStyle);cssStyle.forEach(function(style){ret[style.key]=style.value})}};var toCamelCase=function(str){return str.replace(/-([a-z])/g,function(g){return g[1].toUpperCase()})};var parseColor=function(color){var haxRegex=new RegExp("^#([0-9a-f]{3}|[0-9a-f]{6})$");var rgbRegex=new RegExp("^rgb\\((\\d+),\\s*(\\d+),\\s*(\\d+)\\)$");var nameRegex=new RegExp("^[a-z]+$");if(haxRegex.test(color)){return color}else if(rgbRegex.test(color)){var decimalColors=rgbRegex.exec(color).slice(1);for(var i=0;i<3;i++){var decimalValue=+decimalColors[i];if(decimalValue>255){decimalValue=255}var hexString="0"+decimalValue.toString(16);hexString=hexString.slice(-2);decimalColors[i]=hexString}return"#"+decimalColors.join("")}else if(nameRegex.test(color)){return color}else{console.error('Could not parse color "'+color+'"');return color}};return convertHtml(htmlText)}},{}]},{},[1])(1)}); +(function(f){if(typeof exports==="object"&&typeof module!=="undefined"){module.exports=f()}else if(typeof define==="function"&&define.amd){define([],f)}else{var g;if(typeof window!=="undefined"){g=window}else if(typeof global!=="undefined"){g=global}else if(typeof self!=="undefined"){g=self}else{g=this}g.htmlToPdfmake=f()}})(function(){var define,module,exports;return function(){function r(e,n,t){function o(i,f){if(!n[i]){if(!e[i]){var c="function"==typeof require&&require;if(!f&&c)return c(i,!0);if(u)return u(i,!0);var a=new Error("Cannot find module '"+i+"'");throw a.code="MODULE_NOT_FOUND",a}var p=n[i]={exports:{}};e[i][0].call(p.exports,function(r){var n=e[i][1][r];return o(n||r)},p,p.exports,r,e,n,t)}return n[i].exports}for(var u="function"==typeof require&&require,i=0;i-1)return ret;ret={text:text};if(parentNodeName){applyParentsStyle(ret,element);if(parentNodeName==="a"){ret.link=parentNode.getAttribute("href")}}else{ret=text}}}return ret}case 1:{ret=[];parents.push(nodeName);if(element.childNodes.length===0&&(parents.indexOf("th")>-1||parents.indexOf("td")>-1)){var ancestor=element;var allEmpty=true;while(ancestor.nodeName!=="TH"&&ancestor.nodeName!=="TD"){if(ancestor.textContent!==""){allEmpty=false;break}ancestor=ancestor.parentNode}if(allEmpty)ret.push({text:""})}else{[].forEach.call(element.childNodes,function(child){child=parseElement(child,element,parents);if(child){if(Array.isArray(child)&&child.length===1)child=child[0];ret.push(child)}});parents.pop()}if(ret.length===0)ret="";switch(nodeName){case"svg":{ret={svg:element.outerHTML};ret.style=["html-"+nodeName];break}case"br":{ret="\n";break}case"hr":{var styleHR={width:514,type:"line",margin:[0,12,0,12],thickness:.5,color:"#000000",left:0};if(element.dataset&&element.dataset.pdfmake){dataset=JSON.parse(element.dataset.pdfmake);for(key in dataset){styleHR[key]=dataset[key]}}ret={margin:styleHR.margin,canvas:[{type:styleHR.type,x1:styleHR.left,y1:0,x2:styleHR.width,y2:0,lineWidth:styleHR.thickness,lineColor:styleHR.color}]};break}case"ol":case"ul":{ret={_:ret};ret[nodeName]=ret._;delete ret._;ret.style=["html-"+nodeName];cssClass=element.getAttribute("class");if(cssClass){ret.style=ret.style.concat(cssClass.split(" "))}setComputedStyle(ret,element.getAttribute("style"));break}case"table":{ret={_:ret,table:{body:[]}};ret._.forEach(function(re){if(re.stack){var td=[],rowspan={};re.stack.forEach(function(r,indexRow){var c,cell,i,indexCell;if(r.stack){if(rowspan[indexRow]){rowspan[indexRow].forEach(function(cell){r.stack.splice(cell.index,0,{text:"",style:["html-td","html-tr"],colSpan:cell.colspan})})}for(c=0,cell;c1){for(i=0;i1){for(i=0;i0)ret.table.body.push(td)}else{ret.table.body.push([re])}});delete ret._;setComputedStyle(ret,element.getAttribute("style"));break}case"img":{ret={image:element.getAttribute("src")};ret.style=["html-img"];cssClass=element.getAttribute("class");if(cssClass){ret.style=ret.style.concat(cssClass.split(" "))}if(element.getAttribute("width")){ret.width=parseFloat(element.getAttribute("width"))}if(element.getAttribute("height")){ret.height=parseFloat(element.getAttribute("height"))}setComputedStyle(ret,element.getAttribute("style"));break}case"h1":case"h2":case"h3":case"h4":case"h5":case"h6":{ret={stack:[{text:ret}]};ret.stack[0].style=["html-"+nodeName];cssClass=element.getAttribute("class");if(cssClass){ret.stack[0].style=ret.stack[0].style.concat(cssClass.split(" "))}applyDefaultStyle(ret.stack[0],nodeName);setComputedStyle(ret.stack[0],element.getAttribute("style"));break}}if(ret){if(Array.isArray(ret)){if(ret.length===1&&nodeName!=="tr"){ret=ret[0];if(typeof ret==="string")ret={text:ret};if(ret.text){applyDefaultStyle(ret,nodeName);setComputedStyle(ret,element.getAttribute("style"))}ret.style=(ret.style||[]).concat(["html-"+nodeName]);if(nodeName==="td"||nodeName==="th")ret.style.push("html-tr")}else{isInlineTag=inlineTags.indexOf(nodeName)>-1;hasStackTags=/{"(stack|table|ol|ul|image)"/.test(JSON.stringify(ret));if(nodeName==="div"&&!hasStackTags)ret={text:ret};else if(isInlineTag&&hasStackTags)ret={stack:ret};else if(!isInlineTag)ret={stack:ret};else ret={text:ret};if(isInlineTag){applyDefaultStyle(ret,nodeName)}ret.style=["html-"+nodeName]}applyParentsStyle(ret,element);if(nodeName==="td"||nodeName==="th"){if(element.getAttribute("rowspan"))ret.rowSpan=element.getAttribute("rowspan")*1;if(element.getAttribute("colspan"))ret.colSpan=element.getAttribute("colspan")*1}cssClass=element.getAttribute("class");if(cssClass){ret.style=(ret.style||[]).concat(cssClass.split(" "))}if(ret.text){setComputedStyle(ret,element.getAttribute("style"))}}else if(ret.table||ret.ol||ret.ul){ret.style=["html-"+nodeName];cssClass=element.getAttribute("class");if(cssClass){ret.style=ret.style.concat(cssClass.split(" "))}applyDefaultStyle(ret,nodeName)}if(element.dataset&&element.dataset.pdfmake){dataset=JSON.parse(element.dataset.pdfmake);dist=ret[nodeName]||ret;for(key in dataset){dist[key]=dataset[key]}}cssClass=element.getAttribute("class");if(cssClass&&typeof ret==="object"){ret.style=(ret.style||[]).concat(cssClass.split(" "))}if(typeof ret==="object"&&Array.isArray(ret.style)){ret.style=ret.style.filter(function(value,index,self){return self.indexOf(value)===index})}}return ret}}return""};var applyDefaultStyle=function(ret,nodeName){if(defaultStyles[nodeName]){for(var style in defaultStyles[nodeName]){if(defaultStyles[nodeName].hasOwnProperty(style)){ret[style]=defaultStyles[nodeName][style]}}}};var applyParentsStyle=function(ret,node){var classes=[],defaultStyles=[],cssClass;var inlineParentNode=node.parentNode;while(inlineParentNode){var defaultStyle={};var inlineParentNodeName=inlineParentNode.nodeName.toLowerCase();if(inlineTags.indexOf(inlineParentNodeName)>-1){cssClass=inlineParentNode.getAttribute("class");classes=classes.concat(["html-"+inlineParentNodeName],cssClass||[]);applyDefaultStyle(defaultStyle,inlineParentNodeName);defaultStyles.push(defaultStyle);inlineParentNode=inlineParentNode.parentNode}else break}ret.style=(ret.style||[]).concat(classes);defaultStyles.forEach(function(defaultStyle){for(var key in defaultStyle){if(key.indexOf("margin")===-1&&ret[key]===undefined)ret[key]=defaultStyle[key]}});if(ret.style.length===0)delete ret.style};var computeStyle=function(style){var styleDefs=style.split(";").map(function(style){return style.replace(/\s/g,"").toLowerCase().split(":")});var ret=[];styleDefs.forEach(function(styleDef){var key=styleDef[0];var value=styleDef[1];switch(key){case"margin":{value=value.replace(/(\d+)(\.\d+)?([^\d]+)/g,"$1$2 ").trim().split(" ");if(value.length===1)value=+value[0];else if(value.length===2)value=[+value[1],+value[0]];else if(value.length===3)value=[+value[1],+value[0],+value[1],+value[2]];else if(value.length===4)value=[+value[3],+value[0],+value[1],+value[2]];ret.push({key:key,value:value});break}case"text-align":{ret.push({key:"alignment",value:value});break}case"font-weight":{if(value==="bold")ret.push({key:"bold",value:true});break}case"text-decoration":{ret.push({key:"decoration",value:toCamelCase(value)});break}case"font-style":{if(value==="italic")ret.push({key:"italics",value:true});break}case"color":{ret.push({key:"color",value:parseColor(value)});break}case"background-color":{ret.push({key:"background",value:parseColor(value)});break}default:{if(key.indexOf("-")>-1)key=toCamelCase(key);if(value){value=value.replace(/(\d+)(\.\d+)?([^\d]+)/g,"$1$2 ").trim();if(!isNaN(value))value=+value;ret.push({key:key,value:value})}}}});return ret};var setComputedStyle=function(ret,cssStyle){if(cssStyle){cssStyle=computeStyle(cssStyle);cssStyle.forEach(function(style){ret[style.key]=style.value})}};var toCamelCase=function(str){return str.replace(/-([a-z])/g,function(g){return g[1].toUpperCase()})};var parseColor=function(color){var haxRegex=new RegExp("^#([0-9a-f]{3}|[0-9a-f]{6})$");var rgbRegex=new RegExp("^rgb\\((\\d+),\\s*(\\d+),\\s*(\\d+)\\)$");var nameRegex=new RegExp("^[a-z]+$");if(haxRegex.test(color)){return color}else if(rgbRegex.test(color)){var decimalColors=rgbRegex.exec(color).slice(1);for(var i=0;i<3;i++){var decimalValue=+decimalColors[i];if(decimalValue>255){decimalValue=255}var hexString="0"+decimalValue.toString(16);hexString=hexString.slice(-2);decimalColors[i]=hexString}return"#"+decimalColors.join("")}else if(nameRegex.test(color)){return color}else{console.error('Could not parse color "'+color+'"');return color}};return convertHtml(htmlText)}},{}]},{},[1])(1)}); diff --git a/example.pdf b/example.pdf index 2a376199666cb4f564bb738cd935600eb781c9bb..bb576e3571ec199b64bec503fee3f2aef37957af 100644 GIT binary patch delta 96 zcmZ3vh-u{_rVUrjI86;K3@nTcO)WRyHG3QBoM>uco|KqoZjfwbnQCZZlx&ommSkj_ WYL=2>U~G_PY^PvDNXca0i8283&K;lt delta 96 zcmZ3vh-u{_rVUrjI8BTV3@wa|jSM&6HG3QBY-*aAnw(^0kY=2iXk=+=Y-pHln4Fkw VWNu($VFsk^6l@47nan#;1_0I*9JT-e diff --git a/index.js b/index.js index e1f2859..581bdf8 100644 --- a/index.js +++ b/index.js @@ -124,7 +124,7 @@ module.exports = function(htmlText, options) { var parseElement = function(element, parentNode, parents) { var nodeName = element.nodeName.toLowerCase(); var parentNodeName = (parentNode ? parentNode.nodeName.toLowerCase() : ''); - var ret, text, cssClass, dataset, key, dist, isInlineTag; + var ret, text, cssClass, dataset, key, dist, isInlineTag, hasStackTags; parents = parents || []; // check the node type @@ -140,7 +140,6 @@ module.exports = function(htmlText, options) { if (parentNodeName) { // check if we have inherent styles to apply when a text is inside several applyParentsStyle(ret, element); - // for links if (parentNodeName === "a") { ret.link = parentNode.getAttribute("href"); @@ -328,6 +327,25 @@ module.exports = function(htmlText, options) { setComputedStyle(ret, element.getAttribute("style")); break; } + case "h1": + case "h2": + case "h3": + case "h4": + case "h5": + case "h6": { + // encapsule in a stack + ret = {stack:[{text:ret}]}; + ret.stack[0].style = ['html-'+nodeName]; + cssClass = element.getAttribute("class"); + if (cssClass) { + ret.stack[0].style = ret.stack[0].style.concat(cssClass.split(' ')); + } + // apply default style + applyDefaultStyle(ret.stack[0], nodeName); + // check if the element has a "style" attribute + setComputedStyle(ret.stack[0], element.getAttribute("style")); + break; + } } // add a custom class to let the user customize the element if (ret) { @@ -347,9 +365,15 @@ module.exports = function(htmlText, options) { if (nodeName === "td" || nodeName === "th") ret.style.push('html-tr'); } else { isInlineTag = (inlineTags.indexOf(nodeName) > -1); - - // if we have an inline tag, then we check if we have a non-inline tag in its section - ret = (!isInlineTag || /{"(stack|table|ol|ul|image)"/.test(JSON.stringify(ret)) ? {stack:ret} : {text:ret}); + hasStackTags = /{"(stack|table|ol|ul|image)"/.test(JSON.stringify(ret)); + // if it's a DIV and only inline tags in its section, then we want to use 'text' instead of 'stack' + if (nodeName === 'div' && !hasStackTags) ret = {text:ret}; + // if we have an inline tag with stack tags in its section, then we want to use 'stack' + else if (isInlineTag && hasStackTags) ret = {stack:ret}; + // if it's not an inline tag, then we use 'stack' + else if (!isInlineTag) ret = {stack:ret}; + // otherwise, for inline tags, we use 'text' + else ret = {text:ret}; // we apply the default style for the inline tags if (isInlineTag) { @@ -449,7 +473,8 @@ module.exports = function(htmlText, options) { for (var key in defaultStyle) { if (key.indexOf("margin") === -1 && ret[key] === undefined) ret[key] = defaultStyle[key]; } - }) + }); + if (ret.style.length===0) delete ret.style; } /** diff --git a/package.json b/package.json index 321c09d..569a93a 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "html-to-pdfmake", - "version": "1.2.4", + "version": "1.2.5", "description": "Convert HTML code to PDFMake", "main": "index.js", "scripts": { diff --git a/test/unit.js b/test/unit.js index 649d75d..e02d24a 100644 --- a/test/unit.js +++ b/test/unit.js @@ -76,13 +76,14 @@ test("i",function(t) { t.finish(); }) -// [{"text":"level 1","fontSize":24,"bold":true,"marginBottom":5,"style":["html-h1"]}] +// [{stack:[{text:[{text:'level 1'}],style:[ 'html-h1' ],fontSize:24,bold:true,marginBottom:5}]] test("h1",function(t) { var ret = htmlToPdfMake("

level 1

", window); - t.check(Array.isArray(ret) && ret.length===1, "return is OK"); - ret = ret[0]; + t.check(Array.isArray(ret) && ret[0].stack && Array.isArray(ret[0].stack), "return is OK"); + ret = ret[0].stack[0]; t.check( - ret.text === "level 1" && + Array.isArray(ret.text) && + ret.text[0].text === "level 1" && ret.fontSize === 24 && ret.bold === true && ret.marginBottom === 5 && @@ -95,10 +96,11 @@ test("h1",function(t) { test("h2",function(t) { var ret = htmlToPdfMake("

level 2

", window); - t.check(Array.isArray(ret) && ret.length===1, "return is OK"); - ret = ret[0]; + t.check(Array.isArray(ret) && ret[0].stack && Array.isArray(ret[0].stack), "return is OK"); + ret = ret[0].stack[0]; t.check( - ret.text === "level 2" && + Array.isArray(ret.text) && + ret.text[0].text === "level 2" && ret.fontSize === 22 && ret.bold === true && ret.marginBottom === 5 && @@ -111,10 +113,11 @@ test("h2",function(t) { test("h3",function(t) { var ret = htmlToPdfMake("

level 3

", window); - t.check(Array.isArray(ret) && ret.length===1, "return is OK"); - ret = ret[0]; + t.check(Array.isArray(ret) && ret[0].stack && Array.isArray(ret[0].stack), "return is OK"); + ret = ret[0].stack[0]; t.check( - ret.text === "level 3" && + Array.isArray(ret.text) && + ret.text[0].text === "level 3" && ret.fontSize === 20 && ret.bold === true && ret.marginBottom === 5 && @@ -127,10 +130,11 @@ test("h3",function(t) { test("h4",function(t) { var ret = htmlToPdfMake("

level 4

", window); - t.check(Array.isArray(ret) && ret.length===1, "return is OK"); - ret = ret[0]; + t.check(Array.isArray(ret) && ret[0].stack && Array.isArray(ret[0].stack), "return is OK"); + ret = ret[0].stack[0]; t.check( - ret.text === "level 4" && + Array.isArray(ret.text) && + ret.text[0].text === "level 4" && ret.fontSize === 18 && ret.bold === true && ret.marginBottom === 5 && @@ -143,10 +147,11 @@ test("h4",function(t) { test("h5",function(t) { var ret = htmlToPdfMake("
level 5
", window); - t.check(Array.isArray(ret) && ret.length===1, "return is OK"); - ret = ret[0]; + t.check(Array.isArray(ret) && ret[0].stack && Array.isArray(ret[0].stack), "return is OK"); + ret = ret[0].stack[0]; t.check( - ret.text === "level 5" && + Array.isArray(ret.text) && + ret.text[0].text === "level 5" && ret.fontSize === 16 && ret.bold === true && ret.marginBottom === 5 && @@ -159,10 +164,11 @@ test("h5",function(t) { test("h6",function(t) { var ret = htmlToPdfMake("
level 6
", window); - t.check(Array.isArray(ret) && ret.length===1, "return is OK"); - ret = ret[0]; + t.check(Array.isArray(ret) && ret[0].stack && Array.isArray(ret[0].stack), "return is OK"); + ret = ret[0].stack[0]; t.check( - ret.text === "level 6" && + Array.isArray(ret.text) && + ret.text[0].text === "level 6" && ret.fontSize === 14 && ret.bold === true && ret.marginBottom === 5 &&