Skip to content

Commit

Permalink
v2.5.16
Browse files Browse the repository at this point in the history
Fix for #229
  • Loading branch information
Aymkdn committed Nov 29, 2024
1 parent d020e4f commit 8496679
Show file tree
Hide file tree
Showing 9 changed files with 23 additions and 7 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -373,7 +373,7 @@ Support for various image formats and references:
<img data-src='{"url": "https://example.com/image.jpg", "headers": {"Authorization": "Bearer token"}}'>
```

For Base64 encoded image, please refer to the [PDFMake documentation](https://pdfmake.github.io/docs/document-definition-object/images/)) and [here](https://github.com/Aymkdn/html-to-pdfmake/issues/109#issue-932953144). And you can check [this Stackoverflow question](https://stackoverflow.com/questions/934012/get-image-data-in-javascript/42916772#42916772) to know the different ways to get a base64 encoded content from an image.
For Base64 encoded image, please refer to the [PDFMake documentation](https://pdfmake.github.io/docs/document-definition-object/images/) and [here](https://github.com/Aymkdn/html-to-pdfmake/issues/109#issue-932953144). And you can check [this Stackoverflow question](https://stackoverflow.com/questions/934012/get-image-data-in-javascript/42916772#42916772) to know the different ways to get a base64 encoded content from an image.

## Common Use Cases

Expand Down Expand Up @@ -427,7 +427,7 @@ For Base64 encoded image, please refer to the [PDFMake documentation](https://pd

### Columns

PDFMake has a concept of [`columns`](https://pdfmake.github.io/docs/0.1/document-definition-object/columns/). We use `<div data-pdfmake-type="column"></div>` to identify it.
PDFMake has a concept of [`columns`](https://pdfmake.github.io/docs/0.1/document-definition-object/columns/). We use `<div data-pdfmake-type="columns"></div>` to identify it.

Example to center a table in the page:
```html
Expand Down
2 changes: 1 addition & 1 deletion browser.js

Large diffs are not rendered by default.

1 change: 0 additions & 1 deletion docs/browser-2.5.15.js

This file was deleted.

1 change: 1 addition & 0 deletions docs/browser-2.5.16.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.15.js"></script>
<script src="browser-2.5.16.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.
3 changes: 2 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -509,9 +509,10 @@ function htmlToPdfMake(htmlText, options) {
// if it's a stack, then check if the last child has a "text"
if (ret.stack && !ret.stack[ret.stack.length-1].text) {
// if not, we restructure our node
// by moving the non-stack stuff inside a "text"
text = ret.stack.slice(0, -1);
ret = [
(Array.isArray(text) ? {"stack": text} : {"text": text}),
{"text": text}, // (Array.isArray(text) ? {"stack": text} : {"text": text}),
ret.stack[ret.stack.length-1]
];
}
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.15",
"version": "2.5.16",
"description": "Convert HTML code to PDFMake",
"main": "index.js",
"scripts": {
Expand Down
15 changes: 15 additions & 0 deletions test/unit.js
Original file line number Diff line number Diff line change
Expand Up @@ -1154,5 +1154,20 @@ test("unit tests", function(t) {
t.finish();
});

t.test("ol with ul",function(t) {
var html = `<ol><li><strong>Number 1</strong><span>:</span><ul><li><span>Item</span></li></ul></li></ol>`;
var ret = htmlToPdfMake(html, {
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.ol) && ret.ol.length === 1 && Array.isArray(ret.ol[0].stack), "first stack");
t.check(ret.ol[0].stack.length === 2 && Array.isArray(ret.ol[0].stack[0].text) && ret.ol[0].stack[0].text[0].text === "Number 1", "first text");
t.check(Array.isArray(ret.ol[0].stack[1].ul) && ret.ol[0].stack[1].ul[0].text[0].text === "Item", "first ul");

t.finish();
});

t.finish();
})

0 comments on commit 8496679

Please sign in to comment.