mirror of
https://github.com/storytold/wordcraft.git
synced 2026-11-13 22:12:22 +00:00
Gap 19: ODT index marks as XE fields; updating an index held around its entries
ODT index marks (`text:alphabetical-index-mark`) were dropped. So References › Update Index on an opened ODT index found no entries and left the old list in place. Now: - a mark at a point is Word's `XE` field, its `text:key1`/`text:key2` the levels above its entry; - a mark over text (`-mark-start` … `-mark-end`, in one paragraph) is an `XE` field whose entry is the marked text, which stays text; - `XE` fields are written back as point marks. Engine: Update rebuilt only lists in WordCraft's own form, a paragraph holding the field. A list held as a field around its entries, as ODT and Word files hold an index, bibliography or table of figures, is now first made the field's own paragraph, then rebuilt. That happens only when the field starts its paragraph, so no document text is replaced. A LibreOffice document with an index mark round-trips pixel-identical, the mark kept. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01GBVQLyDnrG8Tn1yDQcUabC
This commit is contained in:
6 files changed
+198
-2
No files matched your search
@@ -65,6 +65,46 @@ fn generated_list_with(s: &mut Session, instr: &str, title: &str, leader: Option
|
||||
update_generated(s)
|
||||
}
|
||||
|
||||
/// Most paragraphs a list held as a field around its entries spans.
|
||||
const MAX_WRAPPED: usize = 10_000;
|
||||
|
||||
/// A generated list (index, bibliography, table of figures or authorities) held as a complex
|
||||
/// field that starts at body block `i` and runs over its entries: its field code and the block
|
||||
/// it ends in. `None` for anything else (a TOC has its own update).
|
||||
fn wrapped_list(s: &Session, i: usize) -> Option<(String, usize)> {
|
||||
let p = s.doc.body.get(i)?.as_para()?;
|
||||
let (off, instr) = p.objects_with_offsets().find_map(|(off, o)| match o {
|
||||
InlineObject::FieldStart { instr, .. } => {
|
||||
let t = instr.trim_start();
|
||||
(t.starts_with("BIBLIOGRAPHY") || t.starts_with("INDEX") || t.starts_with("TOA") || figures_label(t).is_some())
|
||||
.then(|| (off, t.to_string()))
|
||||
}
|
||||
_ => None,
|
||||
})?;
|
||||
// Only when it starts the paragraph: text before it is the document's, not the list's.
|
||||
if !p.text.get(..off).is_some_and(|t| t.chars().all(|c| c.is_whitespace() || c == wordcraft_doc::para::OBJ)) {
|
||||
return None;
|
||||
}
|
||||
// Where it ends: the field end that closes it, nested fields counted.
|
||||
let mut depth = 0usize;
|
||||
for (j, b) in s.doc.body.iter().enumerate().skip(i).take(MAX_WRAPPED) {
|
||||
let Some(q) = b.as_para() else { continue };
|
||||
for o in &q.objects {
|
||||
match o {
|
||||
InlineObject::FieldStart { .. } => depth += 1,
|
||||
InlineObject::FieldEnd => {
|
||||
depth = depth.saturating_sub(1);
|
||||
if depth == 0 {
|
||||
return Some((instr, j));
|
||||
}
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
}
|
||||
None
|
||||
}
|
||||
|
||||
fn list_kind(p: &Paragraph) -> Option<String> {
|
||||
p.objects.iter().find_map(|o| match o {
|
||||
InlineObject::Field { instr, .. } => {
|
||||
@@ -152,6 +192,22 @@ pub(super) const ENTRY_STYLE: &str = "ListEntry";
|
||||
pub fn update_generated(s: &mut Session) -> Result<(), CmdError> {
|
||||
let mut i = 0;
|
||||
while i < s.doc.body.len() {
|
||||
// A list held as a field around its entries (as Word and ODT files hold them): made the
|
||||
// field's own paragraph, as WordCraft inserts one, its old entries rebuilt below.
|
||||
if let Some((instr, last)) = wrapped_list(s, i) {
|
||||
let mut p = Paragraph::default();
|
||||
p.insert_object(
|
||||
0,
|
||||
InlineObject::Field { instr, result: String::new(), locked: false, dirty: false, code: false, form: String::new() },
|
||||
&Default::default(),
|
||||
)?;
|
||||
for _ in i..last {
|
||||
s.doc.remove_block(StoryRef::Body, &Path::top(i + 1))?;
|
||||
}
|
||||
if let Some(b) = s.doc.body.get_mut(i) {
|
||||
*b = wordcraft_doc::para_block(p);
|
||||
}
|
||||
}
|
||||
let kind = s.doc.body.get(i).and_then(|b| b.as_para()).and_then(list_kind);
|
||||
let Some(kind) = kind else {
|
||||
i += 1;
|
||||
|
||||
@@ -65,3 +65,27 @@ fn an_odt_table_of_contents_updates_from_the_headings() {
|
||||
assert_eq!(entries(&s2), ["Planning", "Budget"], "titled: {titled}");
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn an_odt_index_updates_from_its_marks() {
|
||||
// An alphabetical index whose entries are index marks in the text (`XE` fields once open):
|
||||
// Update Index lists them, rather than emptying the index.
|
||||
let content = format!(
|
||||
r#"<office:document-content {NS}><office:body><office:text>
|
||||
<text:alphabetical-index text:name="A"><text:alphabetical-index-source/><text:index-body><text:p>stale, 9</text:p></text:index-body></text:alphabetical-index>
|
||||
<text:p>Clay <text:alphabetical-index-mark text:string-value="kilns"/>is fired; <text:alphabetical-index-mark-start text:id="m"/>glazes<text:alphabetical-index-mark-end text:id="m"/> shine.</text:p>
|
||||
</office:text></office:body></office:document-content>"#
|
||||
);
|
||||
let mut z = zip::ZipWriter::new(std::io::Cursor::new(Vec::new()));
|
||||
let o = zip::write::SimpleFileOptions::default().compression_method(zip::CompressionMethod::Stored);
|
||||
for (name, data) in [("mimetype", "application/vnd.oasis.opendocument.text"), ("content.xml", content.as_str())] {
|
||||
z.start_file(name, o).unwrap();
|
||||
z.write_all(data.as_bytes()).unwrap();
|
||||
}
|
||||
let mut s = Session::new(io::open_bytes("index.odt", &z.finish().unwrap().into_inner()).unwrap());
|
||||
s.run("references.updateIndex", &json!({})).unwrap();
|
||||
let text: Vec<String> = s.doc.body.iter().filter_map(|b| b.as_para()).map(|p| p.text.replace(wordcraft_doc::para::OBJ, "")).collect();
|
||||
assert!(text.iter().any(|t| t.starts_with("glazes")), "{text:?}");
|
||||
assert!(text.iter().any(|t| t.starts_with("kilns")), "{text:?}");
|
||||
assert!(!text.iter().any(|t| t.contains("stale")), "{text:?}");
|
||||
}
|
||||
@@ -19,6 +19,9 @@ use notes::{OpenField, OpenNote, balance_comments};
|
||||
use tables::TableB;
|
||||
use tracked::{DelState, Region, change_mark};
|
||||
|
||||
/// Most index entries over text open at once in a paragraph.
|
||||
const MAX_OPEN_MARKS: usize = 64;
|
||||
|
||||
/// An open frame: its size, picture, alt text, equation, chart and other embedded object.
|
||||
type Frame =
|
||||
(Option<f32>, Option<f32>, Option<Vec<u8>>, String, Option<(String, bool)>, Option<wordcraft_doc::chart::ChartSpec>, Option<model::OdfObject>);
|
||||
@@ -30,6 +33,9 @@ pub(super) struct Body<'a> {
|
||||
pub(super) entries: &'a [String],
|
||||
/// The paragraph before had a page break after it: the next one starts a page.
|
||||
break_next: bool,
|
||||
/// Index entries over text whose end hasn't come (in the paragraph being read): their id,
|
||||
/// keys and where they start: an inline, and a byte offset in it when it is text.
|
||||
index_marks: Vec<(String, (Option<String>, Option<String>), (usize, usize))>,
|
||||
/// A ruby being read: its base text, ruby text, which of them the text goes to (`true`:
|
||||
/// the ruby), and the base's formatting.
|
||||
ruby: Option<(String, String, Option<bool>, Fmt)>,
|
||||
@@ -132,6 +138,7 @@ impl<'a> Body<'a> {
|
||||
forms: Default::default(),
|
||||
break_next: false,
|
||||
ruby: None,
|
||||
index_marks: Vec::new(),
|
||||
manifest: None,
|
||||
containers: vec![Vec::new()],
|
||||
fmt: Vec::new(),
|
||||
@@ -443,6 +450,8 @@ impl Body<'_> {
|
||||
}
|
||||
|
||||
fn end_para(&mut self) {
|
||||
// An index entry is marked within one paragraph.
|
||||
self.index_marks.clear();
|
||||
let Some(mut p) = self.para.take() else { return };
|
||||
self.fmt.pop();
|
||||
// A paragraph ending inside an open insertion has an inserted mark. (Paragraphs that
|
||||
@@ -903,6 +912,60 @@ impl Body<'_> {
|
||||
"line-break" => self.push_text("\n"),
|
||||
// A bookmark (§6.2.1): a point, or the start or end of the text it covers.
|
||||
// A reference mark (§7.6) is a bookmark too: references to it are Word's to bookmarks.
|
||||
// An index entry over text (§8.1.11–8.1.12): an `XE` field at its start, the entry the
|
||||
// marked text (in one paragraph).
|
||||
"alphabetical-index-mark-start" => {
|
||||
if let (Some(id), Some(p)) = (get(a, "text:id"), &self.para)
|
||||
&& self.index_marks.len() < MAX_OPEN_MARKS
|
||||
{
|
||||
let keys = (get(a, "text:key1").map(String::from), get(a, "text:key2").map(String::from));
|
||||
// Where it starts: after the last inline, or inside the text run the marked
|
||||
// text will join.
|
||||
let at = match p.inlines.last() {
|
||||
Some(Inline::Text(t, _)) => (p.inlines.len() - 1, t.len()),
|
||||
_ => (p.inlines.len(), 0),
|
||||
};
|
||||
self.index_marks.push((id.to_string(), keys, at));
|
||||
}
|
||||
}
|
||||
"alphabetical-index-mark-end" => {
|
||||
if let Some(at) = get(a, "text:id").and_then(|id| self.index_marks.iter().position(|(i, ..)| i == id)) {
|
||||
let (_, (k1, k2), (from, off)) = self.index_marks.remove(at);
|
||||
if let Some(p) = &mut self.para {
|
||||
// The marked text: from the offset in the first run on.
|
||||
let text: String = p
|
||||
.inlines
|
||||
.iter()
|
||||
.enumerate()
|
||||
.skip(from)
|
||||
.filter_map(|(k, i)| match i {
|
||||
Inline::Text(t, _) if k == from => t.get(off..),
|
||||
Inline::Text(t, _) => Some(t.as_str()),
|
||||
_ => None,
|
||||
})
|
||||
.collect();
|
||||
if let Some(instr) = super::fields::xe_instr(k1.as_deref(), k2.as_deref(), &text) {
|
||||
let field = Inline::Field { instr, result: String::new(), fmt: Fmt::default() };
|
||||
// Inside a run: split it there.
|
||||
let split = match p.inlines.get_mut(from) {
|
||||
Some(Inline::Text(t, f)) if off > 0 && t.is_char_boundary(off) && off < t.len() => {
|
||||
let rest = t.split_off(off);
|
||||
Some(Inline::Text(rest, f.clone()))
|
||||
}
|
||||
_ => None,
|
||||
};
|
||||
match split {
|
||||
Some(rest) => {
|
||||
p.inlines.insert(from + 1, rest);
|
||||
p.inlines.insert(from + 1, field);
|
||||
}
|
||||
None if off > 0 => p.inlines.insert((from + 1).min(p.inlines.len()), field),
|
||||
None => p.inlines.insert(from.min(p.inlines.len()), field),
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
"bookmark" | "bookmark-start" | "bookmark-end" | "reference-mark" | "reference-mark-start" | "reference-mark-end" => {
|
||||
if let Some(name) = get(a, "text:name").filter(|n| !n.is_empty()) {
|
||||
let name = name.to_string();
|
||||
|
||||
@@ -46,6 +46,8 @@ pub(super) fn instr_of(local: &str, a: &Attrs, picture: impl Fn(&str) -> Option<
|
||||
.filter(|n| !n.is_empty() && n.len() <= MAX_REF_NAME && !n.contains(|c: char| c.is_whitespace() || c == '"' || c == '\\'))
|
||||
};
|
||||
match local {
|
||||
// An index entry at a point (§8.1.10): Word's `XE`, its keys the levels above it.
|
||||
"alphabetical-index-mark" => xe_instr(get(a, "text:key1"), get(a, "text:key2"), get(a, "text:string-value")?),
|
||||
// Numbering figures, tables and the like (§7.4.13): Word's `SEQ` and its number format.
|
||||
"sequence" => {
|
||||
let seq = name("text:name")?;
|
||||
@@ -146,6 +148,15 @@ pub(super) fn element(instr: &str, result: &str, data_style: Option<&str>) -> Op
|
||||
};
|
||||
Some(format!("<text:page-number{fmt} text:select-page=\"current\">{result}</text:page-number>"))
|
||||
}
|
||||
// An index entry: a mark at its place, its first levels the keys (§8.1.10).
|
||||
"XE" => {
|
||||
let entry = instr.get(code.len()..)?.trim_start();
|
||||
let entry = entry.strip_prefix('"').and_then(|t| t.split('"').next())?;
|
||||
let mut levels: Vec<&str> = entry.split(':').map(str::trim).filter(|l| !l.is_empty()).collect();
|
||||
let value = levels.pop()?;
|
||||
let keys: String = levels.iter().take(2).enumerate().map(|(i, k)| format!(" text:key{}=\"{}\"", i + 1, x(k))).collect();
|
||||
Some(format!("<text:alphabetical-index-mark text:string-value=\"{}\"{keys}/>", x(value)))
|
||||
}
|
||||
"REF" | "PAGEREF" => {
|
||||
let name = words.next().filter(|n| !n.starts_with('\\') && n.len() <= MAX_REF_NAME)?;
|
||||
let rest: Vec<&str> = words.collect();
|
||||
@@ -166,6 +177,24 @@ pub(super) fn element(instr: &str, result: &str, data_style: Option<&str>) -> Op
|
||||
}
|
||||
}
|
||||
|
||||
/// Most characters of an index entry's level.
|
||||
const MAX_ENTRY_LEVEL: usize = 255;
|
||||
|
||||
/// The `XE` field code of an index entry `value` under keys `key1` and `key2` (its levels, top
|
||||
/// first). Quotes, which end the entry, and colons, which split levels, are left out of each.
|
||||
/// `None` when the entry is empty.
|
||||
pub(super) fn xe_instr(key1: Option<&str>, key2: Option<&str>, value: &str) -> Option<String> {
|
||||
let clean = |s: &str| {
|
||||
s.chars().filter(|c| !matches!(c, '"' | ':' | '\\') && !c.is_control()).take(MAX_ENTRY_LEVEL).collect::<String>().trim().to_string()
|
||||
};
|
||||
let value = clean(value);
|
||||
if value.is_empty() {
|
||||
return None;
|
||||
}
|
||||
let levels: Vec<String> = [key1, key2].into_iter().flatten().map(clean).filter(|k| !k.is_empty()).chain([value]).collect();
|
||||
Some(format!("XE \"{}\"", levels.join(":")))
|
||||
}
|
||||
|
||||
/// The argument of switch `\sw` in field code `instr` (quoted or one word).
|
||||
fn switch_arg(instr: &str, sw: char) -> Option<String> {
|
||||
let at = instr.find(&format!("\\{sw}"))?;
|
||||
|
||||
@@ -135,3 +135,26 @@ fn hostile_indexes_do_not_panic() {
|
||||
let _ = export(&d).unwrap();
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn index_marks_are_xe_fields_and_written_back() {
|
||||
// An entry at a point (`text:alphabetical-index-mark`, its keys the levels above it) and one
|
||||
// over text (`-mark-start` … `-mark-end`, the entry being the marked text).
|
||||
let body = r#"<text:p>Fruit <text:alphabetical-index-mark text:string-value="apple" text:key1="Fruit"/>is sweet; <text:alphabetical-index-mark-start text:id="m1"/>bananas<text:alphabetical-index-mark-end text:id="m1"/> too.</text:p><text:p><text:alphabetical-index-mark text:string-value="a "quoted" one: here"/></text:p>"#;
|
||||
let content =
|
||||
format!(r#"<office:document-content {NS_T}><office:body><office:text>{body}</office:text></office:body></office:document-content>"#);
|
||||
let d = import(&crate::odt::tests::package(&content, None)).unwrap();
|
||||
let xe: Vec<String> = d
|
||||
.body
|
||||
.iter()
|
||||
.filter_map(|b| b.as_para())
|
||||
.flat_map(|p| p.objects.iter())
|
||||
.filter_map(|o| if let wordcraft_doc::para::InlineObject::Field { instr, .. } = o { Some(instr.clone()) } else { None })
|
||||
.collect();
|
||||
assert_eq!(xe, [r#"XE "Fruit:apple""#, r#"XE "bananas""#, r#"XE "a quoted one here""#]);
|
||||
// The marked text stays text.
|
||||
assert!(d.body.iter().filter_map(|b| b.as_para()).any(|p| p.text.contains("bananas too.")));
|
||||
let c = crate::odt::tests::content_of(&export(&d).unwrap());
|
||||
assert!(c.contains(r#"<text:alphabetical-index-mark text:string-value="apple" text:key1="Fruit"/>"#), "{c}");
|
||||
assert!(c.contains(r#"<text:alphabetical-index-mark text:string-value="bananas"/>"#), "{c}");
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
# File-format parity with Microsoft Word
|
||||
|
||||
> **Last reviewed:** 2026-10-11 · **Last updated:** 2026-11-01 · **Change:** trivial (ODT ruby read and written); previously trivial (ODT page breaks after a paragraph, kept lines, widow control, hyphenation, table alignment and width and row heights); previously trivial (in-line drawings raised or lowered by their run's position; ODT in-line frames keep their place on the baseline; leading's space after the last line; text box borders shown by LibreOffice); previously trivial (ODT form controls opened and saved as content controls); previously trivial (password-protected ODT opened and saved); previously trivial (ODT headers and footers keep their shapes, text boxes, charts and embedded objects on save); previously trivial (ODT embedded spreadsheets and OLE objects kept whole instead of lost; flat ODT sub-documents valid `office:document`s); previously trivial (ODT charts in drawing groups drawn on open); previously trivial (ODT charts opened and saved as editable charts; flat ODT sub-documents no longer end the body); previously trivial (ODT leading read as an at-least spacing); previously trivial (ODT tracked formatting changes; changed regions named by `xml:id`); previously trivial (ODT drop caps; tab stops no longer drop a paragraph's background); previously trivial (flat ODT `.fodt` opened and saved; ODT fidelity re-estimated at ~80%); previously trivial (ODT page settings; a footnote no longer takes a footer's text); previously trivial (ODT dates in their formats, sequences, chapters and references); previously trivial (ODT bookmarks over text); previously trivial (ODT tables of contents and indexes; ODT fidelity re-estimated); previously trivial (ODT polygons, polylines and paths); previously trivial (ODT arrowheads, dashes and gradients); previously trivial (ODT groups of shapes and pictures); previously trivial (ODT rotated and mirrored shapes and pictures); previously trivial (ODT drawing shapes read and written); previously trivial (ODT text box frames keep their line, fill, padding and fit); previously trivial (ODT Asian and complex-script fonts); previously trivial (ODT right-to-left paragraphs); previously trivial (ODT text boxes kept); previously trivial (ODT unnumbered headings detached from the outline); previously trivial (ODT contextual spacing and layout settings); previously trivial (ODT custom character styles kept); previously trivial (ODT list level positions); previously trivial (ODT custom paragraph styles kept); previously trivial (ODT equations written as formula objects); previously trivial (ODT numbered headings written as headings); previously trivial (ODT floating pictures); previously trivial (ODT paragraph borders and background); previously trivial (ODT heading numbering); previously trivial (ODT font-face names); previously trivial (ODT table cell borders and padding); previously trivial (ODT heading, title, quote and preformatted styles keep their look); previously trivial (ODT tab stops read and written); previously trivial (ODT character formatting read and written); previously trivial (ODT lists keep their number formats, bullets and identity); previously trivial (ODT comments read and written); previously trivial (ODT footnotes and endnotes read and written); previously trivial (ODT headers, footers and text fields written; fields read); previously trivial (ODT paragraph spacing, indents and line spacing read and written); previously trivial (a paragraph naming an undefined style is formatted as Normal, as in Word, #5077); previously trivial (a hyperlinked TOC writes its page numbers as `PAGEREF _Toc… \h` fields, as Word does, #5097); previously trivial (HTML import ends the empty comments <!--> and <!---> at once, #5040); previously trivial (chart and SmartArt text the font lacks is drawn in a fallback face, so Chinese labels no longer show boxes, #4720); previously trivial (bibliography sources keep a corporate author (`b:Corporate`): read, written, cited and listed whole, #4848); previously trivial (custom-property bookmark-link preservation, #4767); previously trivial (note conversion preserves content with an ordered reference/run walk, #4750); previously trivial (DOCX comment-ID save lookups); previously trivial (built-in heading styles have their outline level without `w:outlineLvl`, #4696); previously trivial (DOCX comment ranges inside footnotes and endnotes are kept on read, #4548); previously trivial (RTF import and export keep Windows and Enhanced Metafile pictures (`\wmetafile`, `\emfblip`), #4259); previously trivial (#4658 bounds nested Markdown reference-label work); previously trivial (HTML import keeps preformatted lines with CR or CRLF input newlines, #4810); previously trivial (DOCX parts stored under another casing keep their embedded fonts through a save, and a private save of a kept glossary escapes the attribute values it rewrites; previously trivial: the `.doc` reader logs what its copy budget leaves out, once a kind per document; imporLine truncated
|
||||
> **Last reviewed:** 2026-10-11 · **Last updated:** 2026-11-01 · **Change:** trivial (ODT index marks read and written as XE fields; an index held around its entries updates); previously trivial (ODT ruby read and written); previously trivial (ODT page breaks after a paragraph, kept lines, widow control, hyphenation, table alignment and width and row heights); previously trivial (in-line drawings raised or lowered by their run's position; ODT in-line frames keep their place on the baseline; leading's space after the last line; text box borders shown by LibreOffice); previously trivial (ODT form controls opened and saved as content controls); previously trivial (password-protected ODT opened and saved); previously trivial (ODT headers and footers keep their shapes, text boxes, charts and embedded objects on save); previously trivial (ODT embedded spreadsheets and OLE objects kept whole instead of lost; flat ODT sub-documents valid `office:document`s); previously trivial (ODT charts in drawing groups drawn on open); previously trivial (ODT charts opened and saved as editable charts; flat ODT sub-documents no longer end the body); previously trivial (ODT leading read as an at-least spacing); previously trivial (ODT tracked formatting changes; changed regions named by `xml:id`); previously trivial (ODT drop caps; tab stops no longer drop a paragraph's background); previously trivial (flat ODT `.fodt` opened and saved; ODT fidelity re-estimated at ~80%); previously trivial (ODT page settings; a footnote no longer takes a footer's text); previously trivial (ODT dates in their formats, sequences, chapters and references); previously trivial (ODT bookmarks over text); previously trivial (ODT tables of contents and indexes; ODT fidelity re-estimated); previously trivial (ODT polygons, polylines and paths); previously trivial (ODT arrowheads, dashes and gradients); previously trivial (ODT groups of shapes and pictures); previously trivial (ODT rotated and mirrored shapes and pictures); previously trivial (ODT drawing shapes read and written); previously trivial (ODT text box frames keep their line, fill, padding and fit); previously trivial (ODT Asian and complex-script fonts); previously trivial (ODT right-to-left paragraphs); previously trivial (ODT text boxes kept); previously trivial (ODT unnumbered headings detached from the outline); previously trivial (ODT contextual spacing and layout settings); previously trivial (ODT custom character styles kept); previously trivial (ODT list level positions); previously trivial (ODT custom paragraph styles kept); previously trivial (ODT equations written as formula objects); previously trivial (ODT numbered headings written as headings); previously trivial (ODT floating pictures); previously trivial (ODT paragraph borders and background); previously trivial (ODT heading numbering); previously trivial (ODT font-face names); previously trivial (ODT table cell borders and padding); previously trivial (ODT heading, title, quote and preformatted styles keep their look); previously trivial (ODT tab stops read and written); previously trivial (ODT character formatting read and written); previously trivial (ODT lists keep their number formats, bullets and identity); previously trivial (ODT comments read and written); previously trivial (ODT footnotes and endnotes read and written); previously trivial (ODT headers, footers and text fields written; fields read); previously trivial (ODT paragraph spacing, indents and line spacing read and written); previously trivial (a paragraph naming an undefined style is formatted as Normal, as in Word, #5077); previously trivial (a hyperlinked TOC writes its page numbers as `PAGEREF _Toc… \h` fields, as Word does, #5097); previously trivial (HTML import ends the empty comments <!--> and <!---> at once, #5040); previously trivial (chart and SmartArt text the font lacks is drawn in a fallback face, so Chinese labels no longer show boxes, #4720); previously trivial (bibliography sources keep a corporate author (`b:Corporate`): read, written, cited and listed whole, #4848); previously trivial (custom-property bookmark-link preservation, #4767); previously trivial (note conversion preserves content with an ordered reference/run walk, #4750); previously trivial (DOCX comment-ID save lookups); previously trivial (built-in heading styles have their outline level without `w:outlineLvl`, #4696); previously trivial (DOCX comment ranges inside footnotes and endnotes are kept on read, #4548); previously trivial (RTF import and export keep Windows and Enhanced Metafile pictures (`\wmetafile`, `\emfblip`), #4259); previously trivial (#4658 bounds nested Markdown reference-label work); previously trivial (HTML import keeps preformatted lines with CR or CRLF input newlines, #4810); previously trivial (DOCX parts stored under another casing keep their embedded fonts through a save, and a private save of a kept glossary escapes the attribute values it rewriteLine truncated
|
||||
|
||||
Every format Word opens or saves, what WordCraft does with it, and how it's tested. Fidelity is the
|
||||
share of a typical real-world file's content and formatting that survives (read: shows correctly;
|
||||
@@ -57,7 +57,7 @@ Weights are the share of a Word user's file traffic (estimate). Read/write: ✅
|
||||
| PDF export | 8% | W | — | ✅ | ~80% | 6–10 | `crates/pdf/src/tests.rs` | krilla: embedded subsets, selectable text incl. field results (#133); Hebrew and Arabic copy and search as whole words (right-to-left glyphs written in visual order, #1383, also with fonts that draw lam-alef as two glyphs at one x, #2310); All Caps and Small Caps text extracts as the capitals shown, as from Word's PDFs, and never changes the case of other text (#1473), links, outline, tagging. Outline destinations follow leading page breaks to the heading text. Fonts it can't subset become outlines (#132). Print Markup (#589): comments in balloons beside each page (scaled to its paper) and tracked changes; HTML/Markdown/text copies end with a comment list. Horizontal and vertical lines inside groups are drawn (#1474). No PDF/A option, no "best for printing/online" choice |
|
||||
| PDF open (PDF Reflow, Word for Windows) | 1% | R | ❌ | — | 0% | 30–50 | — | Converting a PDF into an editable document. A sibling app (PdfCraft) may supply the parser |
|
||||
| `.rtf` Rich Text Format | 3% | R/W | 🟡 | 🟡 | ~50% | 10–15 | `crates/formats/src/tests.rs` | ~1,500 lines: text, character/paragraph formatting, styles, lists, tables, pictures (`\shppict`, #154; Windows and Enhanced Metafiles, `\wmetafile` and `\emfblip`, read and written, #4259), fields, bookmarks. 8-bit text in the document's code page (`\ansicpg`) or the current font's (`\fcharset`, `\cpg`): Cyrillic, Central European, Greek, Turkish, Hebrew, Arabic, Baltic, Vietnamese, Thai (was Windows-1252 only), Mac OS Roman (`\mac`, `\fcharset77`) and DOS code pages (`\pc` 437, `\pca` 850, `\cpg` 437/737/850/852/857/866, `\fcharset254`) (#1653). East Asian multibyte code pages decoded as runs: 932 Shift-JIS (`\fcharset128`, Japanese), 936 GBK (134, Simplified Chinese), 949 UHC/windows-949 (129, Korean) and 950 Big5 (136, Traditional Chinese) through `\ansicpg`, `\cpg` or the font's charset, escaped or raw, a lead byte and its trail byte together; invalid sequences read as U+FFFD, and a run that starts `EF BB BF` is text, not a BOM (#1653). Pasted from the system clipboard where the platform offers it (Windows, Wayland) when there is no HTML (#687). Tracked insertions and deletions read and written (`\revtbl`, `\revised`/`\deleted`, authors, `\revdttm` dates), so Accept/Reject All work after opening or a round trip; tracked paragraph marks (`\par` inside `\revised`/`\deleted` groups, including a `\sect` inside a deletion) and character and paragraph formatting revisions (`\crauth`/`\crdate` with `\oldcprops`, `\prauth`/`\prdate` with `\oldpprops`) read and written; section and table formatting revisions (`\oldsprops`, `\oldtprops`) not yet. Sections on import (#1378): each `\sect` ends a section with its own page size and orientation, margins, header/footer distance, columns, break type, page-number restart, start and format, title page and headers/footers (those it leaves out link to the previous); export writes every section too (break type, page size and orientation, margins, header/footer distance, columns, page numbering, title page; not headers/footers). Thin: comments, notes, RTL |
|
||||
| `.odt` OpenDocument Text (and flat `.fodt`) | 2% | R/W | 🟡 | 🟡 | ~82% | 30–50 | `crates/formats/src/tests.rs`, `crates/formats/src/odt/tests.rs` and one file per feature in `crates/formats/src/odt/tests_more/`, `crates/engine/tests/it/odt_sections.rs`, `odt_toc.rs`, `odt_fields.rs`, `odt_charts.rs`, `odt_objects.rs`, `odt_password.rs`, `odt_forms.rs`; checked against LibreOffice's own documents (round trips compared page by page) and the ODF 1.3 schema | Ruby (`text:ruby`, §6.4: a base text with ruby text over it) is read as WordCraft's Phonetic Guide and written back as ODF ruby above its base, centred (one inside a tracked change is written as its base text, which the change marks); its own position and alignment aren't kept. Emphasis marks (`style:text-emphasize`), character borders (LibreOffice's `loext:border`) and rotated text (`style:text-rotation-angle`) aren't read. How text flows: a page break after a paragraph (`fo:break-after`, a page break before the next paragraph as Word has it), lines kept together (`fo:keep-together`), widow and orphan control (`fo:widows`/`fo:orphans`: on with any line count, off with none; the counts themselves aren't kept) and hyphenation (`fo:hyphenate`, a paragraph's in ODF and the document's in WordCraft: a document with a hyphenated paragraph hyphenates, its other paragraphs opting out) are read and written; a table's alignment and width (`table:align`, `style:rel-width`, or `style:width` for an aligned table) and its rows' heights (`style:row-height` exact, `style:min-row-height` at least) are read and written. Form controls (`office:forms` controls placed by `draw:control`, ODF 1.3 §13) open as content controls — text fields and text areas as plain text controls, check boxes as check boxes, radio buttons as check boxes with round symbols, list boxes as drop-down lists, combo boxes as combo boxes, date fields as date controls, each with its value, entries and selection, its name as the control's tag and a label as its title — and content controls of those kinds in the body are written back as form controls LibreOffice shows with their values (in headers and footers, as their text); buttons, images, hidden and other controls aren't read, and a control's size and look aren't kept. Password-protected ODT (ODF 1.3 Part 2 §3.4) opens with its password — AES-256-CBC with a SHA-256 or SHA-1 start key and PBKDF2, as LibreOffice writes it; the old Blowfish encryption is refused with a message saying so — and a document opened with a password, or saved with one (Save with password), is written encrypted the way LibreOffice encrypts (every file but the `mimetype` and manifest; each with its own salt and initialisation vector; SHA-256 checksums), which LibreOffice opens with the password. Flat OpenDocument text (`.fodt`: the whole document in one `office:document`, pictures inline as base64 `office:binary-data`, formulas inline) is opened and saved as a package is, both validating against the schema. Tables of contents and other indexes (`text:table-of-content`, `text:illustration-index`/`text:table-index`, `text:alphabetical-index`, `text:bibliography`) open as Word's `TOC` (levels from the source's `text:outline-level`; `\c` with the caption name for a table of figures), `INDEX` and `BIBLIOGRAPHY` fields — in the title paragraph when the index has one, as WordCraft inserts a table, else around the entries — so References › Update Table regenerates them; LibreOffice's Contents 1–10, Contents Heading and Figure Index 1 styles are WordCraft's TOC 1–9, TOC Heading and Table of Figures; WordCraft's tables are written back as ODF indexes with their source and entry templates (LibreOffice updates them), entries' links in the Index Link style; user and object indexes are read as their paragraphs; index marks (`text:alphabetical-index-mark`, Word's `XE`) are not read. Custom character styles (a common text style other than LibreOffice's link, note-mark and list-label styles kept as a character style with its name, parent and own formatting, its text in it; written back as common text styles), custom paragraph styles (a common style other than Standard, the kinds' and the note texts' kept as a document style with its name, parent and own formatting, its paragraphs in it rather than given its formatting directly; written back as common styles, named so LibreOffice keeps them), paragraph borders (each side's line and padding) and background, heading numbering (`text:outline-style`: each level's format, prefix, suffix, levels shown and start number the headings through their styles, as Word's numbered headings, and are written back), styles (the file's own Heading 1–6, Title, Quotations and Preformatted Text definitions give those styles' look on open — font, size, percent sizes included, bold, colour, spacing, alignment, keep with next — and saving writes the document's own style definitions rather than fixed ones), tab stops (left, centre, right, deLine truncated
|
||||
| `.odt` OpenDocument Text (and flat `.fodt`) | 2% | R/W | 🟡 | 🟡 | ~82% | 30–50 | `crates/formats/src/tests.rs`, `crates/formats/src/odt/tests.rs` and one file per feature in `crates/formats/src/odt/tests_more/`, `crates/engine/tests/it/odt_sections.rs`, `odt_toc.rs`, `odt_fields.rs`, `odt_charts.rs`, `odt_objects.rs`, `odt_password.rs`, `odt_forms.rs`; checked against LibreOffice's own documents (round trips compared page by page) and the ODF 1.3 schema | Ruby (`text:ruby`, §6.4: a base text with ruby text over it) is read as WordCraft's Phonetic Guide and written back as ODF ruby above its base, centred (one inside a tracked change is written as its base text, which the change marks); its own position and alignment aren't kept. Emphasis marks (`style:text-emphasize`), character borders (LibreOffice's `loext:border`) and rotated text (`style:text-rotation-angle`) aren't read. How text flows: a page break after a paragraph (`fo:break-after`, a page break before the next paragraph as Word has it), lines kept together (`fo:keep-together`), widow and orphan control (`fo:widows`/`fo:orphans`: on with any line count, off with none; the counts themselves aren't kept) and hyphenation (`fo:hyphenate`, a paragraph's in ODF and the document's in WordCraft: a document with a hyphenated paragraph hyphenates, its other paragraphs opting out) are read and written; a table's alignment and width (`table:align`, `style:rel-width`, or `style:width` for an aligned table) and its rows' heights (`style:row-height` exact, `style:min-row-height` at least) are read and written. Form controls (`office:forms` controls placed by `draw:control`, ODF 1.3 §13) open as content controls — text fields and text areas as plain text controls, check boxes as check boxes, radio buttons as check boxes with round symbols, list boxes as drop-down lists, combo boxes as combo boxes, date fields as date controls, each with its value, entries and selection, its name as the control's tag and a label as its title — and content controls of those kinds in the body are written back as form controls LibreOffice shows with their values (in headers and footers, as their text); buttons, images, hidden and other controls aren't read, and a control's size and look aren't kept. Password-protected ODT (ODF 1.3 Part 2 §3.4) opens with its password — AES-256-CBC with a SHA-256 or SHA-1 start key and PBKDF2, as LibreOffice writes it; the old Blowfish encryption is refused with a message saying so — and a document opened with a password, or saved with one (Save with password), is written encrypted the way LibreOffice encrypts (every file but the `mimetype` and manifest; each with its own salt and initialisation vector; SHA-256 checksums), which LibreOffice opens with the password. Flat OpenDocument text (`.fodt`: the whole document in one `office:document`, pictures inline as base64 `office:binary-data`, formulas inline) is opened and saved as a package is, both validating against the schema. Tables of contents and other indexes (`text:table-of-content`, `text:illustration-index`/`text:table-index`, `text:alphabetical-index`, `text:bibliography`) open as Word's `TOC` (levels from the source's `text:outline-level`; `\c` with the caption name for a table of figures), `INDEX` and `BIBLIOGRAPHY` fields — in the title paragraph when the index has one, as WordCraft inserts a table, else around the entries — so References › Update Table regenerates them; LibreOffice's Contents 1–10, Contents Heading and Figure Index 1 styles are WordCraft's TOC 1–9, TOC Heading and Table of Figures; WordCraft's tables are written back as ODF indexes with their source and entry templates (LibreOffice updates them), entries' links in the Index Link style; user and object indexes are read as their paragraphs; index marks are Word's `XE` fields — a mark at a point (`text:alphabetical-index-mark`, its `text:key1`/`text:key2` the levels above its entry) and one over text (`-mark-start`…`-mark-end` in one paragraph, its entry the marked text) — and `XE` fields are written as point marks, so References › Update Index rebuilds an ODT index from its entries (an index or other generated list held as a field around its entries, as ODT and Word files hold it, is first made the field's own paragraph, as WordCraft inserts one). Custom character styles (a common text style other than LibreOffice's link, note-mark and list-label styles kept as a character style with its name, parent and own formatting, its text in it; written back as common text styles), custom paragraph styles (a common style other than Standard, the kinds' and the note texts' kept as a document style with its name, parent and own formatting, its paragraphs in it rather than given its formatting directly; written back as common styles, named so LibreOffice keeps them), paragraph borders (each side's line and padding) and background, heading numbering (`text:outline-style`: each level's format, prefix, sLine truncated
|
||||
| `.txt` Plain text | 2% | R/W | ✅ | ✅ | ~95% | 1–2 | unit tests | Encoding detection. Files with other extensions (`.m3u`/`.m3u8` playlists, logs, config files, no extension) open as text when they are text, Word and RTF files by their signature; binary files are refused (#569). A Word or RTF extension that contradicts the content also opens by signature, as in Word: RTF saved as `.doc` (hh.ru résumés, accounting exports), a `.docx` renamed `.doc`, a Word 97-2003 file renamed `.docx`; a Word XML Document (Word 2003 XML or Flat OPC) or a web page (`<html>`, `<!DOCTYPE html>`) under a `.doc`, `.docx` or `.rtf` name opens as what it is (#2853, `tests::word_xml_and_web_pages_saved_as_doc_open_by_content`). Word's encoding choice dialog and line-ending options missing; such files save only through Save As |
|
||||
| `.htm/.html` Web Page and Web Page, Filtered | 1% | R/W | 🟡 | 🟡 | ~60% | 6–10 | `crates/formats/src/tests.rs` | Tables (#102), relative pictures embedded (#113), missing `</head>` tolerated (#154); the empty comments `<!-->` and `<!--->` end at once instead of swallowing the rest of the page (#5040). Header cells (`<th>`) bold unless their CSS says otherwise; `text-align` on a cell, or inherited from its row, row group or table, aligns the cell's paragraphs (#1381). HTML gives no page size, so it opens on the region's paper (A4 or Letter), as Markdown and plain text do; `@page` isn't read (#1381). No Word "Web Page" (with `_files` folder) round-trip. The same reader takes HTML from the system clipboard: Paste keeps another program's formatting (a Word document, a web page; Windows' "HTML Format" header understood), Merge Formatting keeps its emphasis (#687). A pasted `<blockquote>` (LibreOffice's paragraph indented on both sides) becomes a Normal paragraph indented by the page's `blockquote` margins, else 0.5 in each side; opening an .html file keeps it as the Quote style (#1270). Equations are written as MathML (with the linear format as a UnicodeMath annotation) and read back from MathML: our annotation, else the presentation elements, else a TeX annotation (#816). A copy of one equation alone also goes in the clipboard's MathML formats (Windows "MathML" and "MathML Presentation", macOS `public.mathml.presentation` and `public.mathml`; W3C MathML 3 §6.2.4), which Microsoft documents Word reading first when it pastes math (#1297; the paste into Word is not yet verified); Ruby (furigana, phonetic guides) is written as `<ruby>base<rt>reading</rt></ruby>` in the base text's formatting and read back from `<ruby>`/`<rb>`/`<rt>` (`<rp>` fallback parentheses dropped; malformed markup keeps its text), so docx/doc → HTML → doc keeps the annotation; HTML states no alignment, size or raise, so the Phonetic Guide's defaults apply (#1681) CRLF and lone CR input newlines normalize before tokenization, preserving preformatted lines and leaving decoded character references separate (#4810). |
|
||||
| `.mht/.mhtml` Single File Web Page | <1% | R/W | ❌ | ❌ | 0% | 3–5 | — | |
|
||||
@@ -279,6 +279,7 @@ Custom document properties retain their bookmark link targets through DOCX saves
|
||||
|
||||
| Date | Change | Summary |
|
||||
|---|---|---|
|
||||
| 2026-11-01 | trivial | ODT: index marks (`text:alphabetical-index-mark`, at a point or over text) were dropped, so updating an opened index emptied it; they are read as `XE` fields and written back as marks, and Update Index rebuilds a list held as a field around its entries (ODT's and Word's form) instead of leaving it as it was (`odt::tests_more::indexes::index_marks_are_xe_fields_and_written_back`, `odt_toc.rs::an_odt_index_updates_from_its_marks`) |
|
||||
| 2026-11-01 | trivial | ODT: ruby (`text:ruby`) was read as its base and ruby text run together and written as plain text; it is read as a Phonetic Guide and written back as ODF ruby, which LibreOffice shows over its base (`odt::tests_more::ruby`) |
|
||||
| 2026-11-01 | trivial | ODT: a page break after a paragraph (lost, so a two-page document saved as one page), lines kept together, widow and orphan control, hyphenation (the document hyphenates when a paragraph does), a table's alignment and width and its rows' heights are read and written; a LibreOffice document with them round-trips at 573 px instead of 4 407 and keeps its pages (`odt::tests_more::flow_breaks`) |
|
||||
| 2026-11-01 | trivial | Layout: an in-line picture, shape or chart moves with its run's raise or lowering (Word's `w:position`), the line growing to hold it. ODT: an in-line frame centred on or hanging from the baseline keeps that place (read as that lowering, written back as `from-top`) instead of standing on the baseline; leading's extra space after the last line is kept; a text box's frame derives from the Frame style, without which LibreOffice ignored its border. LibreOffice round trips: shapes 13 864 → 1 273 px, spacing 2 973 → 706 px, text box 736 → 0 px (`layout::tests::an_inline_picture_moves_with_its_runs_position`, `odt::tests_more::floats::an_inline_frame_keeps_its_place_on_the_baseline`, `odt::tests_more::text_boxes::a_text_box_frame_derives_from_the_frame_style`) |
|
||||
|
||||
Reference in new issue
Block a user