Skip to content

Commit

Permalink
2.5.14
Browse files Browse the repository at this point in the history
fixed #227
  • Loading branch information
Aymkdn committed Nov 2, 2024
1 parent 6dbe199 commit ce1e1a6
Show file tree
Hide file tree
Showing 7 changed files with 34 additions and 5 deletions.
2 changes: 1 addition & 1 deletion browser.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion docs/browser-2.5.13.js → docs/browser-2.5.14.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion docs/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ <h1>HTML to PDFMake convertor</h1>
<div id="pdf_ie" style="display:none;padding:3em">The PDF file is sent to you for download. Use a modern browser (like Chrome or Firefox) to display the PDF in this page.</div>
</div>
</div>
<script src="browser-2.5.13.js"></script>
<script src="browser-2.5.14.js"></script>
<script src="https://cdn.jsdelivr.net/npm/pdfmake@latest/build/pdfmake.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/pdfmake@latest/build/vfs_fonts.js"></script>
<script>
Expand Down
Binary file modified example.pdf
Binary file not shown.
7 changes: 6 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -548,7 +548,10 @@ function htmlToPdfMake(htmlText, options) {
var setLink = function(pointer, href) {
pointer = pointer || {text:''}; // for link without any text
if (Array.isArray(pointer.text)) {
return setLink(pointer.text[0], href);
pointer.text = pointer.text.map(function(text) {
return setLink(text, href);
});
return pointer;
} else if (Array.isArray(pointer.stack)) {
// if we have a more complex layer
pointer.stack = pointer.stack.map(function(stack) {
Expand All @@ -563,6 +566,8 @@ function htmlToPdfMake(htmlText, options) {
}
if (element.getAttribute("href")) {
ret = setLink(ret, element.getAttribute("href"));
// reduce the complexity when only 1 text
if (Array.isArray(ret.text) && ret.text.length === 1) ret = ret.text[0];
ret.nodeName = "A";
}
break;
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "html-to-pdfmake",
"version": "2.5.13",
"version": "2.5.14",
"description": "Convert HTML code to PDFMake",
"main": "index.js",
"scripts": {
Expand Down
24 changes: 24 additions & 0 deletions test/unit.js
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,30 @@ test("unit tests", function(t) {
t.finish();
})

t.test("a with subtag",function(t) {
var ret = htmlToPdfMake('<a href="https://www.somewhere.com">link <strong>something</strong></a>', {window:window});
if (debug) console.log(JSON.stringify(ret));
t.check(Array.isArray(ret) && ret.length===1, "return is OK");
ret = ret[0];
t.check(Array.isArray(ret.text) && ret.text.length === 2, "array");
t.check(ret.text[0].text === "link ", "text 1");
t.check(ret.text[1].text === "something", "text 2");
t.check(ret.text[0].color === "blue", "color 1");
t.check(ret.text[1].color === "blue", "color 2");
t.check(ret.text[0].link === "https://www.somewhere.com", "link 1");
t.check(ret.text[1].link === "https://www.somewhere.com", "link 2");
t.check(ret.style[0] === 'html-a', "class");

t.finish();
})
[
{"text":[
{"text":"link ","color":"blue","decoration":["underline"],"style":["html-a"],"link":"https://www.somewhere.com"},
{"text":"something","nodeName":"STRONG","color":"blue","decoration":["underline"],"bold":true,"style":["html-strong","html-a"],"link":"https://www.somewhere.com"}
],
"nodeName":"A","color":"blue","decoration":["underline"],"style":["html-a"]}
]

t.test("strike",function(t) {
var ret = htmlToPdfMake("<strike>strike</strike>", {window:window});
if (debug) console.log(JSON.stringify(ret));
Expand Down

0 comments on commit ce1e1a6

Please sign in to comment.