Skip to content

Commit 7f65fad

Browse files
NadeemShadanNadeem Shadanliborm85
authored
fix: render empty list entries (#2893)
* fix: render empty list entries * update example * update changelog --------- Co-authored-by: Nadeem Shadan <nadeem.s@iinerds.com> Co-authored-by: Libor M. <liborm85@gmail.com>
1 parent 8bd5b33 commit 7f65fad

4 files changed

Lines changed: 39 additions & 1 deletion

File tree

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
- Used fetch API for downloading fonts and images
66
- Update Roboto font (version 3.014)
7+
- Fixed render empty list entries
78

89
## 0.3.0-beta.18 - 2025-05-09
910

examples/lists.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -388,6 +388,23 @@ var docDefinition = {
388388
{ text: 'item 3', listType: 'circle' }
389389
]
390390
},
391+
{ text: '\n\nOrdered list with an empty item:', style: 'header' },
392+
{
393+
ol: [
394+
'First item',
395+
'Second item',
396+
'',
397+
'Fourth item'
398+
]
399+
},
400+
{ text: '\n\nUnordered list with an empty item:', style: 'header' },
401+
{
402+
ul: [
403+
'First bullet',
404+
'',
405+
'Third bullet'
406+
]
407+
},
391408
],
392409
styles: {
393410
header: {

src/LayoutBuilder.js

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,17 @@ class LayoutBuilder {
7272
return false;
7373
}
7474

75-
linearNodeList = linearNodeList.filter(node => node.positions.length > 0);
75+
const hasRenderableContent = node => {
76+
if (!node || node.positions.length === 0) {
77+
return false;
78+
}
79+
if (node.text === '' && !node.listMarker) {
80+
return false;
81+
}
82+
return true;
83+
};
84+
85+
linearNodeList = linearNodeList.filter(hasRenderableContent);
7686

7787
linearNodeList.forEach(node => {
7888
let nodeInfo = {};

src/TextBreaker.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,22 @@ import StyleContextStack from './StyleContextStack';
99
*/
1010
const splitWords = (text, noWrap) => {
1111
let words = [];
12+
if (text === undefined || text === null) {
13+
text = '';
14+
} else {
15+
text = String(text);
16+
}
1217

1318
if (noWrap) {
1419
words.push({ text: text });
1520
return words;
1621
}
1722

23+
if (text.length === 0) {
24+
words.push({ text: '' });
25+
return words;
26+
}
27+
1828
let breaker = new LineBreaker(text);
1929
let last = 0;
2030
let bk;

0 commit comments

Comments
 (0)