Skip to main content

odox_core/
lib.rs

1//! `OpenDocument`, read and written: the package, its XML, its styles, and the
2//! three bodies that an ODF document can have.
3//!
4//! # Bytes in, bytes out
5//!
6//! Nothing here opens a file. A [`Package`] is made from a byte slice and
7//! turned back into a `Vec<u8>`, which is what lets the same code serve a
8//! desktop window, a sandboxed macOS application that may only replace the
9//! file it was handed, a browser, and a test that never touches a disk.
10//!
11//! # What it does not understand, it keeps
12//!
13//! The document is held as the XML tree it was parsed from, not as a summary of
14//! the parts this crate has opinions about. An element nobody here has heard of
15//! keeps its attributes, its children and its position, and is written back
16//! where it was found. A viewer does not need that; an editor built on a model
17//! that discarded the unread nine tenths of ODF would destroy every document it
18//! saved, and by then the model is load-bearing everywhere.
19//!
20//! Typed reading is therefore a *view* over the tree rather than a replacement
21//! for it: [`Styles`] resolves a style name through its inheritance chain, and
22//! the three document types in [`doc`] index the body for the application that
23//! draws it.
24//
25// Author: David M. Anderson
26// Built with AI assistance (Claude, Anthropic)
27
28#![forbid(unsafe_code)]
29#![warn(missing_docs, clippy::pedantic)]
30#![allow(clippy::must_use_candidate)]
31
32pub mod doc;
33pub mod draw;
34mod error;
35mod meta;
36mod package;
37mod style;
38mod value;
39pub mod xml;
40
41pub use doc::Document;
42pub use error::Error;
43pub use meta::Meta;
44pub use package::{Package, Part};
45pub use style::{
46    Border, Break, CellProperties, Edges, Family, Fill, Gradient, GradientStyle, GraphicProperties,
47    PageLayout, ParagraphProperties, Position, Properties, Style, Styles, TextAlign,
48    TextProperties, VerticalAlign,
49};
50pub use value::{Color, Length, Measure, Percent};
51pub use xml::{Element, Name, Node, Ns};
52
53/// The media type of each format this crate reads, as written in a package's
54/// `mimetype` entry and in the desktop's media-type database.
55pub mod media_type {
56    /// Text document: `.odt`.
57    pub const TEXT: &str = "application/vnd.oasis.opendocument.text";
58    /// A text document written as a web page: also `.odt`, and a media type of
59    /// its own rather than a variant of the one above. It is what `LibreOffice`
60    /// writes for a document converted from HTML, and it is read the same way.
61    pub const TEXT_WEB: &str = "application/vnd.oasis.opendocument.text-web";
62    /// Spreadsheet: `.ods`.
63    pub const SPREADSHEET: &str = "application/vnd.oasis.opendocument.spreadsheet";
64    /// Presentation: `.odp`.
65    pub const PRESENTATION: &str = "application/vnd.oasis.opendocument.presentation";
66
67    /// Every media type a text document may declare.
68    pub const TEXT_ANY: &[&str] = &[TEXT, TEXT_WEB];
69    /// Every media type a spreadsheet may declare.
70    pub const SPREADSHEET_ANY: &[&str] = &[SPREADSHEET];
71    /// Every media type a presentation may declare.
72    pub const PRESENTATION_ANY: &[&str] = &[PRESENTATION];
73}