Skip to content

Commit 1962b36

Browse files
FredTregsimonbengtsson
authored andcommitted
doc(split): adding comment on nbsp splitting
1 parent 8e01e3e commit 1962b36

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

src/widthCalculator.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,10 @@ function calculate(doc: DocHandler, table: Table) {
7878
const padding = cell.padding('horizontal')
7979
cell.contentWidth = getStringWidth(cell.text, cell.styles, doc) + padding
8080

81+
// Using /[^\S\u00A0]+/ instead of \s ensures that we split the text on
82+
// all whitespace except non-breaking spaces (\u00A0). We need to
83+
// preserve them in the split process to ensure correct word separation
84+
// and width calculation.
8185
const longestWordWidth = getStringWidth(
8286
cell.text.join(' ').split(/[^\S\u00A0]+/),
8387
cell.styles,

0 commit comments

Comments
 (0)