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;
33mod error;
34mod meta;
35mod package;
36mod style;
37mod value;
38pub mod xml;
39
40pub use doc::Document;
41pub use error::Error;
42pub use meta::Meta;
43pub use package::{Package, Part};
44pub use style::{
45    Border, Break, CellProperties, Edges, Family, GraphicProperties, PageLayout,
46    ParagraphProperties, Position, Properties, Style, Styles, TextAlign, TextProperties,
47    VerticalAlign,
48};
49pub use value::{Color, Length, Measure, Percent};
50pub use xml::{Element, Name, Node, Ns};
51
52/// The media type of each format this crate reads, as written in a package's
53/// `mimetype` entry and in the desktop's media-type database.
54pub mod media_type {
55    /// Text document: `.odt`.
56    pub const TEXT: &str = "application/vnd.oasis.opendocument.text";
57    /// A text document written as a web page: also `.odt`, and a media type of
58    /// its own rather than a variant of the one above. It is what `LibreOffice`
59    /// writes for a document converted from HTML, and it is read the same way.
60    pub const TEXT_WEB: &str = "application/vnd.oasis.opendocument.text-web";
61    /// Spreadsheet: `.ods`.
62    pub const SPREADSHEET: &str = "application/vnd.oasis.opendocument.spreadsheet";
63    /// Presentation: `.odp`.
64    pub const PRESENTATION: &str = "application/vnd.oasis.opendocument.presentation";
65
66    /// Every media type a text document may declare.
67    pub const TEXT_ANY: &[&str] = &[TEXT, TEXT_WEB];
68    /// Every media type a spreadsheet may declare.
69    pub const SPREADSHEET_ANY: &[&str] = &[SPREADSHEET];
70    /// Every media type a presentation may declare.
71    pub const PRESENTATION_ANY: &[&str] = &[PRESENTATION];
72}