Skip to content

Commit 4ab6ef7

Browse files
YousefEDareknawo
authored andcommitted
list support
1 parent 17b4609 commit 4ab6ef7

File tree

2 files changed

+65
-15
lines changed

2 files changed

+65
-15
lines changed

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

Lines changed: 64 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,20 @@ const createTableStyle = (exporter: ODTExporter<any, any, any>) => {
108108
return cellName;
109109
};
110110

111+
const wrapWithLists = (
112+
content: React.ReactNode,
113+
level: number
114+
): React.ReactNode => {
115+
if (level <= 0) {
116+
return content;
117+
}
118+
return (
119+
<TextList>
120+
<TextListItem>{wrapWithLists(content, level - 1)}</TextListItem>
121+
</TextList>
122+
);
123+
};
124+
111125
export const odtBlockMappingForDefaultSchema: BlockMapping<
112126
DefaultBlockSchema,
113127
any,
@@ -144,21 +158,57 @@ export const odtBlockMappingForDefaultSchema: BlockMapping<
144158
);
145159
},
146160

147-
bulletListItem: (block, exporter) => (
148-
<TextList text:style-name="WWNum1">
149-
<TextListItem>
150-
<TextP>{exporter.transformInlineContent(block.content)}</TextP>
151-
</TextListItem>
152-
</TextList>
153-
),
161+
/**
162+
* Note: we wrap each list item in it's own list element.
163+
* This is not the cleanest solution, it would be nicer to recognize subsequent
164+
* list items and wrap them in the same list element.
165+
*
166+
* However, Word DocX -> ODT export actually does the same thing, so
167+
* for now it seems reasonable.
168+
*
169+
* (LibreOffice does nicely wrap the list items in the same list element)
170+
*/
171+
bulletListItem: (block, exporter, nestingLevel) => {
172+
const styleName = createParagraphStyle(
173+
exporter as ODTExporter<any, any, any>,
174+
block.props
175+
);
176+
return (
177+
<TextList text:style-name="WWNum1">
178+
<TextListItem>
179+
{wrapWithLists(
180+
<TextP text:style-name={styleName}>
181+
{exporter.transformInlineContent(block.content)}
182+
</TextP>,
183+
nestingLevel
184+
)}
185+
</TextListItem>
186+
</TextList>
187+
);
188+
},
154189

155-
numberedListItem: (block, exporter) => (
156-
<TextList text:style-name="No_20_List">
157-
<TextListItem>
158-
<TextP>{exporter.transformInlineContent(block.content)}</TextP>
159-
</TextListItem>
160-
</TextList>
161-
),
190+
numberedListItem: (block, exporter, nestingLevel, numberedListIndex) => {
191+
const styleName = createParagraphStyle(
192+
exporter as ODTExporter<any, any, any>,
193+
block.props
194+
);
195+
// continue numbering from the previous list item if this is not the first item
196+
const continueNumbering = (numberedListIndex || 0) > 1 ? "true" : "false";
197+
return (
198+
<TextList
199+
text:style-name="No_20_List"
200+
text:continue-numbering={continueNumbering}>
201+
<TextListItem>
202+
{wrapWithLists(
203+
<TextP text:style-name={styleName}>
204+
{exporter.transformInlineContent(block.content)}
205+
</TextP>,
206+
nestingLevel
207+
)}
208+
</TextListItem>
209+
</TextList>
210+
);
211+
},
162212

163213
checkListItem: (block, exporter) => (
164214
<TextP>

packages/xl-odt-exporter/src/odt/odtExporter.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ export class ODTExporter<
123123
);
124124

125125
const content = await this.mapBlock(
126-
block,
126+
block as any,
127127
nestingLevel,
128128
numberedListIndex
129129
);

0 commit comments

Comments
 (0)