Commit 54187b18af

54187b18afb4e8119e69da306ccc7ea88e66ccc8

parent: 2df4420ff5

Verified · cmc

cmc <hello@cleberg.net> · 2026-11-20 17:00 UTC

Refuse ODT tables in blocks inside lists; no default author on iOS

Layout: unified · split

Sources/OrgCore/Export/ODTExport.swift +15 −11
@@ -219,11 +219,9 @@ final class ODTRenderer {
219219 }
220220 // `org-odt--enumerate`: numbered within the closest numbered heading at level 2 or
221221 // above, else through the document.
222 var counts: [String: Int] = [:]
223222 for (index, item) in enumerables.enumerated() {
224223 let scope = item.ancestors.reversed().first { headings[$0].map { $0.relative <= 2 && $0.number != nil } ?? false }
225224 let ordinal = enumerables[...index].filter { $0.category == item.category && (scope.map($0.ancestors.contains) ?? true) }.count
226 counts[item.category, default: 0] += 1
227225 let sequence = (scope.flatMap { headings[$0]?.number }.map { $0.map(String.init).joined(separator: ".") + "." } ?? "") + String(ordinal)
228226 let named = names.contains { $0.key == item.key }
229227 let variable = ["Table": "Table", "Figure": "Illustration", "Listing": "Listing"][item.category]!
@@ -471,7 +469,7 @@ final class ODTRenderer {
471469 return code(lines)
472470 case .tableEl:
473471 // ox-odt strips table.el tables, the list around them closed and opened again.
474 return frames.isEmpty ? "" : "\n" + reopening(nil)
472 return frames.isEmpty ? "" : "\n" + reopening(nil, for: node)
475473 default:
476474 // Comments, property drawers, planning, clocks, footnote definitions, formulas.
477475 return ""
@@ -529,7 +527,7 @@ final class ODTRenderer {
529527 let parentLow = heading.ancestors.last.flatMap { headings[$0]?.lowLevel } ?? false
530528 out += "\n<text:list text:style-name=\"\(style)\" text:continue-numbering=\"\(parentLow)\">"
531529 }
532 frames.append(Frame(style: style))
530 frames.append(Frame(style: style, heading: true))
533531 let body = "\n<text:p text:style-name=\"Text_20_body\">\(extra)\(anchored)</text:p>" + (contents ? node.children.filter { $0.kind != .heading }.map(element).joined() : "")
534532 let frame = frames.removeLast()
535533 out += "\n<text:list-item>\n\(body)\n\(frame.header ? "</text:list-header>" : "</text:list-item>")"
@@ -596,9 +594,11 @@ final class ODTRenderer {
596594
597595 // MARK: - Lists
598596
599 /// An open list item, closed and opened again around a table.
597 /// An open list item, closed and opened again around a table; `heading` for a heading
598 /// deeper than `H`.
600599 private struct Frame {
601600 var style: String
601 var heading = false
602602 var header = false
603603 }
604604
@@ -664,9 +664,14 @@ final class ODTRenderer {
664664 return "<text:span text:style-name=\"OrgCode\">\(mark)</text:span>"
665665 }
666666
667 /// `org-odt-table`'s list handling: the open lists closed, `inner` in an indented section,
668 /// the lists opened again, the innermost item as a header.
669 private func reopening(_ inner: String?) -> String {
667 /// `org-odt-table`'s list handling for `node`: the open lists closed, `inner` in an indented
668 /// section, the lists opened again, the innermost item as a header.
669 private func reopening(_ inner: String?, for node: SyntaxNode) -> String {
670 // ox-odt doesn't close the lists around a table in a block, and writes XML that doesn't
671 // nest.
672 if let parent = node.parent, parent.kind != .item, parent.kind != .section, frames.contains(where: { !$0.heading }) {
673 return fail("ODT export doesn't support a table in a block inside a list")
674 }
670675 var closing: [String] = []
671676 for frame in frames.reversed() {
672677 closing.append(frame.header ? "</text:list-header>" : "</text:list-item>")
@@ -790,7 +795,7 @@ final class ODTRenderer {
790795 }.joined(separator: "\n")
791796 var out = caption.map { "\n<text:p text:style-name=\"Table\">\($0)</text:p>" } ?? ""
792797 out += "\n<table:table table:style-name=\"\(style)\">" + columnSpecs + "\n" + body + "</table:table>"
793 return "\n" + reopening(out)
798 return "\n" + reopening(out, for: node)
794799 }
795800
796801 /// `org-odt-format-label` as a definition: a bookmark, then the category, sequence number
@@ -879,8 +884,7 @@ final class ODTRenderer {
879884
880885 /// `org-odt-do-format-code`: one paragraph per line, the last one styled apart.
881886 private func code(_ lines: [String], refs: [Int: String] = [:], retain: Bool = false, loc: Int? = nil, emptyLast: Bool = false) -> String {
882 var lines = lines
883 if emptyLast { lines.append("") }
887 let lines = emptyLast ? lines + [""] : lines
884888 let out = lines.enumerated().map { index, line -> String in
885889 var text = line
886890 if let ref = refs[index + 1], retain { text += " (\(ref))" }
Sources/OrgstarMobile/ExportMenu.swift +1 −1
@@ -111,7 +111,7 @@ struct OrgExport: Transferable {
111111 }
112112 try content.write(to: url, atomically: true, encoding: .utf8)
113113 case .odt:
114 try ODTExport.document(text, settings: settings, path: path, author: NSFullUserName(), language: OrgPreferences.exportLanguage())
114 try ODTExport.document(text, settings: settings, path: path, language: OrgPreferences.exportLanguage())
115115 .write(to: url, options: .atomic)
116116 case .icalendar:
117117 try ICalendarFiles.export(self.text, path: path, settings: settings, options: OrgPreferences.icalendarOptions(),
Tests/OrgCoreTests/ODTExportTests.swift +1
@@ -490,6 +490,7 @@ struct ODTExportTests {
490490 "#+ATTR_ODT: :style TableWithHeaderRowAndColumn\n| a |\n",
491491 "Code src_python[:exports code]{1 + 1} here.\n",
492492 "#+DATE: 2024\n#+begin_annotation\nNote.\n#+end_annotation\n",
493 "- a quote\n #+begin_quote\n | q |\n #+end_quote\n",
493494 ])
494495 func refuses(_ text: String) {
495496 #expect(throws: ODTExport.Failure.self) { try ODTExport.document(text, path: "/tmp/doc.org") }
docs/manual/guide/12-export.org +2 −2
@@ -252,7 +252,7 @@ For Org's own ASCII layout, with underlined headings and drawn tables, use Expor
252252
253253Export to ODT writes an OpenDocument text file (=.odt=) for LibreOffice, Pages or Word. orgstar writes it itself, on the Mac and on iOS, the way Emacs's =ox-odt= does under =emacs -Q=: the same headings, paragraphs, lists, tables, links, notes and images, with ox-odt's style names, so a template that restyles ox-odt's output restyles this one too.
254254
255- The title, subtitle (=#+SUBTITLE:=), author and date come first, then the table of contents and the text. Without =#+AUTHOR:=, the author is your account's full name, as =user-full-name= is in Emacs. Without =#+TITLE:= there is no title.
255- The title, subtitle (=#+SUBTITLE:=), author and date come first, then the table of contents and the text. On the Mac, without =#+AUTHOR:=, the author is your account's full name, as =user-full-name= is in Emacs. Without =#+TITLE:= there is no title.
256256- Headings are numbered by the word processor, to the depth =num= gives. Headings deeper than =H= become list items. =#+TOC: headlines= puts a table of contents where it is; =local= limits it to the section.
257257- Footnotes are the word processor's own notes. A note referred to again shows its number.
258258- Tables keep their header rows, alignment cookies, column groups and cell borders. A table inside a list item ends the list, sits indented below it, and the list carries on after it, as in ox-odt.
@@ -261,7 +261,7 @@ Export to ODT writes an OpenDocument text file (=.odt=) for LibreOffice, Pages o
261261- =#+ODT:= lines, =#+BEGIN_EXPORT odt= blocks and =@@odt:...@@= snippets go in as they are.
262262- The styles (=styles.xml=) are orgstar's own: A4 pages with 2 cm margins. =#+ODT_STYLES_FILE:= is not read.
263263
264The export stops with a message, instead of writing something different from ox-odt, for: a link that leads nowhere, an image file that can't be read, inline tasks, table templates (=#+ATTR_ODT: :style=), a link without a description to a =<<target>>= or to a code line that isn't numbered, an inline source block exported as code, an annotation in a dated document, and =#+TOC:= with =:target=. ODT export is always the whole document: the export dialog's *Body only* doesn't apply.
264The export stops with a message, instead of writing something different from ox-odt, for: a link that leads nowhere, an image file that can't be read, inline tasks, table templates (=#+ATTR_ODT: :style=), a link without a description to a =<<target>>= or to a code line that isn't numbered, an inline source block exported as code, a table in a quote or other block inside a list, an annotation in a dated document, and =#+TOC:= with =:target=. ODT export is always the whole document: the export dialog's *Body only* doesn't apply.
265265
266266* Markdown export
267267