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