🐛(export) fix export unsupported colors

Some colors bind to a text style are not supported.
It comes often from a paste style, we don't
display them if they are not supported by the
editor.
This commit is contained in:
Anthony LC
2025-11-14 12:23:34 +01:00
parent c8955133a4
commit a4e3168682
5 changed files with 97 additions and 4 deletions

View File

@@ -23,8 +23,9 @@ export const blockMappingParagraphPDF: DocsExporterPDF['mappings']['blockMapping
});
}
}
return (
<Text key={block.id}>
<Text key={'paragraph' + block.id}>
{exporter.transformInlineContent(block.content)}
</Text>
);

View File

@@ -2,7 +2,7 @@
* We use mainly the Blocknotes code, mixed with @ag-media/react-pdf-table
* to have a better Table support.
* See:
* https://github.com/TypeCellOS/BlockNote/blob/004c0bf720fe1415c497ad56449015c5f4dd7ba0/packages/xl-pdf-exporter/src/pdf/util/table/Table.tsx
* https://github.com/TypeCellOS/BlockNote/blob/main/packages/xl-pdf-exporter/src/pdf/util/table/Table.tsx
*
* We succeeded to manage the colspan, but rowspan is not supported yet.
*/
@@ -92,11 +92,12 @@ export const blockMappingTablePDF: DocsExporterPDF['mappings']['blockMapping']['
color:
cellProps.textColor === 'default'
? undefined
: options.colors[cellProps.textColor].text,
: options.colors?.[cellProps.textColor]?.text,
backgroundColor:
cellProps.backgroundColor === 'default'
? undefined
: options.colors[cellProps.backgroundColor].background,
: options.colors?.[cellProps.backgroundColor]
?.background,
textAlign: cellProps.textAlignment,
},
];

View File

@@ -39,5 +39,39 @@ export const docxDocsSchemaMappings: DocsExporterDocx['mappings'] = {
shading: { fill: 'DCDCDC' },
}
: {},
// If the color is not defined, we fall back to default colors
backgroundColor: (val, exporter) => {
if (!val) {
return {};
}
const backgroundColor = exporter.options.colors?.[val]?.background;
if (!backgroundColor) {
return {};
}
return {
shading: {
fill: backgroundColor.slice(1),
},
};
},
// If the color is not defined, we fall back to default colors
textColor: (val, exporter) => {
if (!val) {
return {};
}
const color = exporter.options.colors?.[val]?.text;
if (!color) {
return {};
}
return {
color: color.slice(1),
};
},
},
};

View File

@@ -32,5 +32,30 @@ export const odtDocsSchemaMappings: DocsExporterODT['mappings'] = {
},
styleMapping: {
...odtDefaultSchemaMappings.styleMapping,
textColor: (val, exporter): Record<string, string> => {
if (!val) {
return {};
}
const color = exporter.options.colors?.[val]?.text;
if (!color) {
return {};
}
return { 'fo:color': color };
},
backgroundColor: (val, exporter): Record<string, string> => {
if (!val) {
return {};
}
const color = exporter.options.colors?.[val]?.background;
if (!color) {
return {};
}
return { 'fo:background-color': color };
},
},
};

View File

@@ -39,5 +39,37 @@ export const pdfDocsSchemaMappings: DocsExporterPDF['mappings'] = {
// that is not available in italics
code: (enabled?: boolean) =>
enabled ? { fontFamily: 'Courier', backgroundColor: '#dcdcdc' } : {},
// If the color is not defined, we fall back to default colors
textColor: (val, exporter) => {
if (!val) {
return {};
}
const color = exporter.options.colors?.[val]?.text;
if (!color) {
return {};
}
return {
color,
};
},
// If the color is not defined, we fall back to default colors
backgroundColor: (val, exporter) => {
if (!val) {
return {};
}
const backgroundColor = exporter.options.colors?.[val]?.background;
if (!backgroundColor) {
return {};
}
return {
backgroundColor,
};
},
},
};