# Input and export formats

> Import DOCX, ODT, RTF, Markdown, plain text, and HTML. Export DOCX, PDF, HTML, Markdown, and plain text.

Six input formats parse into the same document model:

| Format | Extensions | Fidelity |
| --- | --- | --- |
| DOCX | `.docx` | Full fidelity; untouched content round-trips byte for byte on export. |
| ODT | `.odt` | Formatting, lists, tables, images, footnotes, headers/footers, comments, tracked changes. Import-only. |
| RTF | `.rtf` | Formatting, lists, tables, images, footnotes, headers/footers, comments, tracked changes. Import-only. |
| Markdown | `.md`, `.markdown` | Headings, lists, tables, code, inline formatting, links. |
| Plain text | `.txt` | Paragraphs split on blank lines. |
| HTML | `.html`, `.htm` | Structural markup, lists, tables, links, inline formatting. |

```tsx
<ReviseEditor
  initialDocuments={[
    { id: "contract", source: docxFile },
    { id: "report", source: odtFile },
    { id: "letter", source: rtfFile },
    { id: "notes", source: markdownFile },
    { id: "brief", source: htmlFile },
  ]}
/>
```

<Note>
  `docx` is accepted as a legacy alias for `source`. Pass one or the other.
</Note>

## Format detection

Checked in order:

1. Explicit `format` on the document input.
2. Filename extension (`File` only).
3. MIME type (`File` or `Blob`).
4. Fallback: `"docx"`.

For in-memory `Blob` or `ArrayBuffer` inputs without a filename or MIME type, pass `format` explicitly (otherwise they are parsed as DOCX and non-DOCX content fails):

```ts
await editor.documents.open({
  id: "imported",
  source: await response.blob(),
  format: "html",
});
```

Recognized binary MIME types:
- DOCX: `application/vnd.openxmlformats-officedocument.wordprocessingml.document`
- ODT: `application/vnd.oasis.opendocument.text`
- RTF: `application/rtf`, `text/rtf`, `application/x-rtf`, `text/richtext`

## Format details

<AccordionGroup>
  <Accordion title="DOCX">
    Preserves styles, fonts, tables, images, sections, page setup, headers/footers, footnotes/endnotes, comments, tracked changes, and Word Content Controls (`w:sdt` at block, inline, row, cell, and nested levels—including tags, aliases, IDs, and bindings; programmatic SDT read/populate APIs are not yet exposed). Relationship- and namespace-based parsing handles custom prefixes, ISO/IEC 29500 Strict packages, and non-standard part paths; non-canonical packages export as regenerated DOCX (`fidelity.fallbackCode: "nonCanonicalSource"`). Strict value-level fidelity (e.g., percentage table widths) is partial.
  </Accordion>
  <Accordion title="ODT">
    Resolves style properties directly onto runs and paragraphs (fonts, sizes, colors, highlights, inline styles, alignment, indents, spacing, borders, shading, page breaks). Preserves list numbering and continuations, merged table cells and column widths, images, footnotes/endnotes, headers/footers, comments, tracked insertions/deletions, and page size/margins. Floating pictures/text boxes import inline at their anchor; charts and embedded objects import as preview images when present. Named style definitions are not preserved.
  </Accordion>
  <Accordion title="RTF">
    Imports Word, WordPad, TextEdit, and LibreOffice RTF: character and paragraph formatting, heading styles, list tables and WordPad bullets, tables (merged cells, column widths), PNG/JPEG/WMF/EMF images, hyperlinks, footnotes/endnotes, headers/footers, comments, tracked changes, page setup, and Windows/East Asian code pages. Nested tables are flattened into the outer cell; multi-column sections import as single-column.
  </Accordion>
  <Accordion title="Markdown">
    Maps headings, lists, tables, code blocks, links, and emphasis to document blocks with default page setup and no tracked changes.
  </Accordion>
  <Accordion title="Plain text">
    Splits paragraphs on blank lines.
  </Accordion>
  <Accordion title="HTML">
    Maps structural markup to document blocks; strips `<script>`, `<style>`, and layout CSS. `<pre>` maps to a code block, `<caption>` to an adjacent paragraph, `<br>` inside a heading to a line break, and `<br>` inside a paragraph to a paragraph split.
  </Accordion>
</AccordionGroup>

## Titles

If `title` is omitted on a `File` input, the filename without its extension is used (`Master Agreement.docx` → `"Master Agreement"`).

## Export

`tools.export()` supports five output formats:

```ts
const docx = await editor.tools.export(); // .docx, tracked changes intact
const clean = await editor.tools.export({ format: "docx", mode: "final" });
const pdf = await editor.tools.export({ format: "pdf" });
const html = await editor.tools.export({ format: "html" });
const markdown = await editor.tools.export({ format: "markdown" });
```

| Format | Notes |
| --- | --- |
| `docx` (default) | Writes tracked changes and comments as native Word markup. Untouched content from an imported `.docx` exports byte for byte. |
| `pdf` | Paginated with embedded fonts. Supported in browser and `revise/server` (server PDFs omit math formulas). |
| `html` | Standalone HTML page with styles. |
| `markdown` | Headings, lists, tables, links, code, and math. |
| `txt` | Plain text. |

Modes:

- `"review"` (default): `.docx` retains pending tracked changes and comments; other formats export with changes accepted.
- `"final"`: accepts all pending changes and strips comments. In the browser, a final `.docx` is regenerated; on `revise/server`, untouched bytes from the original `.docx` are preserved via grafting.

Any imported format (ODT, RTF, Markdown, HTML, plain text) can export to `.docx`. On Node, [`revise/server`](https://revise.io/developer/docs/editor-sdk/api/backend)'s `doc.export({ format, mode })` takes the same options and additionally returns `fidelity` and `warnings`.

### Degraded PDF output

If required fonts, KaTeX assets, glyphs, or text shaping are unavailable (e.g., `https://revise.io` is blocked and assets are not mirrored via `setAssetBaseUrl()`), PDF export succeeds with substitute fonts unless you inspect warnings or enable `strict: true`:

```ts
const pdf = await editor.tools.export({
  format: "pdf",
  onWarnings: (warnings) => console.warn(warnings), // called only when degraded
});

try {
  await editor.tools.export({ format: "pdf", strict: true });
} catch (error) {
  if (error instanceof ReviseExportError) showRetry(error.warnings);
}
```

On `revise/server`, `doc.export()` reports these in `warnings`, and `strict: true` throws [`ReviseError`](https://revise.io/developer/docs/editor-sdk/api/library#errors) with `code: "export_degraded"`. Because server PDF export omits math formulas, `strict: true` rejects documents containing math.

### Links in exported files

Stored link targets are preserved verbatim on import and edit. On export:

| Target | DOCX, PDF, Markdown | HTML |
| --- | --- | --- |
| `http:`, `https:`, `mailto:`, `tel:`, relative paths, `#fragments` | Link | Link |
| Other schemes (`ftp:`, `zotero:`, `obsidian:`, …) | Link | Plain text |
| `javascript:`, `vbscript:`, `livescript:`, `data:` | Plain text | Plain text |

Scheme matching normalizes case and ASCII control/whitespace characters per browser URL parsing. Markdown escapes link-delimiting characters. Images follow the same rules except `data:image/…` is preserved. RTF and ODT imports strip unsafe targets at parse time.

Exports are not a security boundary: apply your own URL policy when rendering exported Markdown or link targets read from `getDocument()` / tools. Untouched content grafted from an imported `.docx` keeps its original hyperlink targets unchanged.
