Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feature: odt exporter #1331

Merged
merged 45 commits into from
Mar 4, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
45 commits
Select commit Hold shift + click to select a range
a1cc2b1
odt export wip
YousefED Dec 18, 2024
9b35042
fix heading style
YousefED Dec 18, 2024
b4853bf
tabs
YousefED Dec 18, 2024
a1ac263
fix style basics
YousefED Dec 18, 2024
db00fb6
remove files
YousefED Dec 18, 2024
59a0dfa
remove files
YousefED Dec 18, 2024
c843810
block props basics
YousefED Dec 19, 2024
4c34462
table styles
YousefED Dec 19, 2024
eb04674
start with lists
YousefED Dec 19, 2024
c6b49bb
update styles
YousefED Dec 20, 2024
17b4609
fixes
YousefED Dec 20, 2024
4ab6ef7
list support
YousefED Dec 20, 2024
c64317c
odt exporter
areknawo Feb 5, 2025
8fcda07
fix buffer import
areknawo Feb 5, 2025
4d56181
PR feedback implementation
areknawo Feb 10, 2025
c9feab3
remove sharp
areknawo Feb 10, 2025
d865b21
implement PR feedback
areknawo Feb 12, 2025
01aa14d
fix: e2e snapshots
areknawo Feb 12, 2025
855e6db
fix: Improve ODT exporter Word compatibility
areknawo Feb 19, 2025
7b9f540
paragraph style improvements
areknawo Feb 20, 2025
f26a061
accept xml doc or string in options
areknawo Feb 20, 2025
5eb96e9
update snapshots
areknawo Feb 20, 2025
f6d308b
Merge remote-tracking branch 'origin/main' into feature/odt-export
YousefED Feb 20, 2025
4480920
fix build
YousefED Feb 20, 2025
0ce2587
fix: File extension detection, header/footer options
areknawo Feb 20, 2025
6cee3b8
fix
YousefED Feb 24, 2025
bf39f3d
Merge remote-tracking branch 'origin/main' into feature/odt-export
YousefED Feb 24, 2025
4dd4516
fix
YousefED Feb 24, 2025
0a2628c
small fixes
YousefED Feb 24, 2025
2983725
feedback
areknawo Feb 26, 2025
2beac8b
update snapshots
areknawo Feb 26, 2025
4e966a4
fix lint issue
areknawo Feb 26, 2025
072ce3b
Add ODT docs to menu
areknawo Feb 26, 2025
79eea41
Merge remote-tracking branch 'origin/main' into feature/odt-export
YousefED Mar 3, 2025
e9636f9
package json
YousefED Mar 3, 2025
a035241
fix bullet styles
YousefED Mar 4, 2025
32b2c1a
address feedback
YousefED Mar 4, 2025
8f912de
update snaps
YousefED Mar 4, 2025
358c2bc
extract imageutil and remove sharp
YousefED Mar 4, 2025
9705d77
fix: throw error when invalid dimensions
nperez0111 Mar 4, 2025
09fed26
fix: rm unused link
nperez0111 Mar 4, 2025
98cb419
docs: update new prosemirror-view version
nperez0111 Mar 4, 2025
a45e212
fix: stop-gap for tables not exporting
nperez0111 Mar 4, 2025
157c732
chore: update snap
nperez0111 Mar 4, 2025
3eebfe6
Merge branch 'main' into feature/odt-export
nperez0111 Mar 4, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion docs/pages/docs/editor-api/_meta.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,6 @@
"converting-blocks": "",
"server-processing": "",
"export-to-pdf": "",
"export-to-docx": ""
"export-to-docx": "",
"export-to-odt": ""
}
104 changes: 104 additions & 0 deletions docs/pages/docs/editor-api/export-to-odt.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
---
title: Export to ODT (Open Document Text)
description: Export BlockNote documents to an ODT (Open Document Text) file.
imageTitle: Export to ODT
path: /docs/export-to-odt
---

import { Example } from "@/components/example";
import { Callout } from "nextra/components";

# Exporting blocks to ODT

It's possible to export BlockNote documents to ODT, completely client-side.

<Callout type={"info"}>
This feature is provided by the `@blocknote/xl-odt-exporter`. `xl-` packages
are fully open source, but released under a copyleft license. A commercial
license for usage in closed source, proprietary products comes as part of the
[Business subscription](/pricing).
</Callout>

First, install the `@blocknote/xl-odt-exporter` package:

```bash
npm install @blocknote/xl-odt-exporter
```

Then, create an instance of the `ODTExporter` class. This exposes the following methods:

```typescript
import {
ODTExporter,
odtDefaultSchemaMappings,
} from "@blocknote/xl-odt-exporter";

// Create the exporter
const exporter = new ODTExporter(editor.schema, odtDefaultSchemaMappings);

// Convert the blocks to a ODT document (Blob)
const odtDocument = await exporter.toODTDocument(editor.document);
```

See the [full example](/examples/interoperability/converting-blocks-to-odt) below:

<Example name="interoperability/converting-blocks-to-odt" />

### Customizing the ODT output file

`toODTDocument` takes an optional `options` parameter, which allows you to customize different options (like headers and footers).

Example usage:

```typescript
const odt = await exporter.toODTDocument(testDocument, {
// XML string
footer: "<text:p>FOOTER</text:p>",
// XMLDocument
header: new DOMParser().parseFromString(
`<text:p xmlns:text="urn:oasis:names:tc:opendocument:xmlns:text:1.0">HEADER</text:p>`,
"text/xml",
),
});
```

### Custom mappings / custom schemas

The `ODTExporter` constructor takes a `schema`, `mappings` and `options` parameter.
A _mapping_ defines how to convert a BlockNote schema element (a Block, Inline Content, or Style) to the [ODT](https://docs.oasis-open.org/office/OpenDocument/v1.3/os/part3-schema/OpenDocument-v1.3-os-part3-schema.html) XML element.
If you're using a [custom schema](/docs/custom-schemas) in your editor, or if you want to overwrite how default BlockNote elements are converted to ODT XML elements, you can pass your own `mappings`:

For example, use the following code in case your schema has an `extraBlock` type:

```tsx
import {
ODTExporter,
odtDefaultSchemaMappings,
} from "@blocknote/xl-odt-exporter";

new ODTExporter(schema, {
blockMapping: {
...odtDefaultSchemaMappings.blockMapping,
myCustomBlock: (block, exporter) => {
return <text:p>My custom block</text:p>;
},
},
inlineContentMapping: odtDefaultSchemaMappings.inlineContentMapping,
styleMapping: odtDefaultSchemaMappings.styleMapping,
});
```

### Exporter options

The `ODTExporter` constructor takes an optional `options` parameter.
While conversion happens on the client-side, the default setup uses a server hosted proxy to resolve files:

```typescript
const defaultOptions = {
// a function to resolve external resources in order to avoid CORS issues
// by default, this calls a BlockNote hosted server-side proxy to resolve files
resolveFileUrl: corsProxyResolveFileUrl,
// the colors to use in the ODT for things like highlighting, background colors and font colors.
colors: COLORS_DEFAULT, // defaults from @blocknote/core
};
```
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ import "@blocknote/core/fonts/inter.css";
import { BlockNoteView } from "@blocknote/mantine";
import "@blocknote/mantine/style.css";
import {
SuggestionMenuController,
getDefaultReactSlashMenuItems,
getPageBreakReactSlashMenuItems,
SuggestionMenuController,
useCreateBlockNote,
} from "@blocknote/react";
import {
Expand All @@ -35,7 +35,7 @@ export default function App() {
content: [
{
type: "text",
text: "Welcome to this",
text: "Welcome to this ",
styles: {
italic: true,
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ import "@blocknote/core/fonts/inter.css";
import { BlockNoteView } from "@blocknote/mantine";
import "@blocknote/mantine/style.css";
import {
SuggestionMenuController,
getDefaultReactSlashMenuItems,
getPageBreakReactSlashMenuItems,
SuggestionMenuController,
useCreateBlockNote,
} from "@blocknote/react";
import {
Expand All @@ -31,7 +31,7 @@ export default function App() {
content: [
{
type: "text",
text: "Welcome to this",
text: "Welcome to this ",
styles: {
italic: true,
},
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"playground": true,
"docs": true,
"author": "areknawo",
"tags": [""],
"dependencies": {
"@blocknote/xl-odt-exporter": "latest"
},
"pro": true
}
Loading
Loading