Skip to content

Commit 643ad0b

Browse files
fix: Code block PDF export (BLO-987) (#2725)
* Updated code block PDF conversion and styling * pdated test snapshots
1 parent 1b53232 commit 643ad0b

3 files changed

Lines changed: 9 additions & 7 deletions

File tree

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1085,8 +1085,7 @@
10851085
>
10861086
<VIEW
10871087
style={{
1088-
backgroundColor: '#161616',
1089-
color: '#ffffff',
1088+
border: '1px solid #000000',
10901089
fontFamily: 'GeistMono',
10911090
fontSize: 12,
10921091
lineHeight: 1.25,

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1093,8 +1093,7 @@
10931093
>
10941094
<VIEW
10951095
style={{
1096-
backgroundColor: '#161616',
1097-
color: '#ffffff',
1096+
border: '1px solid #000000',
10981097
fontFamily: 'GeistMono',
10991098
fontSize: 12,
11001099
lineHeight: 1.25,

packages/xl-pdf-exporter/src/pdf/defaultSchema/blocks.tsx

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,12 @@ export const pdfBlockMappingForDefaultSchema: BlockMapping<
114114
);
115115
},
116116
codeBlock: (block) => {
117-
const textContent = (block.content as StyledText<any>[])[0]?.text || "";
117+
// Code blocks should always contain a single `StyledText` inline content.
118+
// However, if this is not the case for whatever reason, we can merge the
119+
// text content of all `StyledText` content in them.
120+
const textContent = (block.content as StyledText<any>[])
121+
.map((item) => item.text)
122+
.join("");
118123
const lines = textContent.split("\n").map((line, index) => {
119124
const indent = line.match(/^\s*/)?.[0].length || 0;
120125

@@ -135,8 +140,7 @@ export const pdfBlockMappingForDefaultSchema: BlockMapping<
135140
wrap={false}
136141
style={{
137142
padding: 24 * PIXELS_PER_POINT,
138-
backgroundColor: "#161616",
139-
color: "#ffffff",
143+
border: "1px solid #000000",
140144
lineHeight: 1.25,
141145
fontSize: FONT_SIZE * PIXELS_PER_POINT,
142146
fontFamily: "GeistMono",

0 commit comments

Comments
 (0)