Skip to content

Commit 9eca3a8

Browse files
committed
fix: preserve leading whitespace in PDF output using nbsp
1 parent 5ca0572 commit 9eca3a8

File tree

3 files changed

+7
-3
lines changed

3 files changed

+7
-3
lines changed

packages/xl-pdf-exporter/src/pdf/__snapshots__/example.jsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -869,7 +869,7 @@
869869
Styled Text
870870
</TEXT>
871871
<TEXT style={{}}>
872-
{' '}
872+
 
873873
</TEXT>
874874
<LINK href="https://www.blocknotejs.org">
875875
<TEXT style={{}}>

packages/xl-pdf-exporter/src/pdf/__snapshots__/exampleWithHeaderAndFooter.jsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -877,7 +877,7 @@
877877
Styled Text
878878
</TEXT>
879879
<TEXT style={{}}>
880-
{' '}
880+
 
881881
</TEXT>
882882
<LINK href="https://www.blocknotejs.org">
883883
<TEXT style={{}}>

packages/xl-pdf-exporter/src/pdf/pdfExporter.tsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,9 +118,13 @@ export class PDFExporter<
118118
public transformStyledText(styledText: StyledText<S>) {
119119
const stylesArray = this.mapStyles(styledText.styles);
120120
const styles = Object.assign({}, ...stylesArray);
121+
const textWithLeadingNbsp = styledText.text.replace(
122+
/(^|\n) +/g,
123+
(leadingWhiteSpaces) => leadingWhiteSpaces.replace(/ /g, "\u00A0"),
124+
);
121125
return (
122126
<Text style={styles} key={styledText.text}>
123-
{styledText.text}
127+
{textWithLeadingNbsp}
124128
</Text>
125129
);
126130
}

0 commit comments

Comments
 (0)