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 {
219 } 219 }
220 // `org-odt--enumerate`: numbered within the closest numbered heading at level 2 or 220 // `org-odt--enumerate`: numbered within the closest numbered heading at level 2 or
221 // above, else through the document. 221 // above, else through the document.
222 var counts: [String: Int] = [:]
223 for (index, item) in enumerables.enumerated() { 222 for (index, item) in enumerables.enumerated() {
224 let scope = item.ancestors.reversed().first { headings[$0].map { $0.relative <= 2 && $0.number != nil } ?? false } 223 let scope = item.ancestors.reversed().first { headings[$0].map { $0.relative <= 2 && $0.number != nil } ?? false }
225 let ordinal = enumerables[...index].filter { $0.category == item.category && (scope.map($0.ancestors.contains) ?? true) }.count 224 let ordinal = enumerables[...index].filter { $0.category == item.category && (scope.map($0.ancestors.contains) ?? true) }.count
226 counts[item.category, default: 0] += 1
227 let sequence = (scope.flatMap { headings[$0]?.number }.map { $0.map(String.init).joined(separator: ".") + "." } ?? "") + String(ordinal) 225 let sequence = (scope.flatMap { headings[$0]?.number }.map { $0.map(String.init).joined(separator: ".") + "." } ?? "") + String(ordinal)
228 let named = names.contains { $0.key == item.key } 226 let named = names.contains { $0.key == item.key }
229 let variable = ["Table": "Table", "Figure": "Illustration", "Listing": "Listing"][item.category]! 227 let variable = ["Table": "Table", "Figure": "Illustration", "Listing": "Listing"][item.category]!
@@ -471,7 +469,7 @@ final class ODTRenderer {
471 return code(lines) 469 return code(lines)
472 case .tableEl: 470 case .tableEl:
473 // ox-odt strips table.el tables, the list around them closed and opened again. 471 // 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)
475 default: 473 default:
476 // Comments, property drawers, planning, clocks, footnote definitions, formulas. 474 // Comments, property drawers, planning, clocks, footnote definitions, formulas.
477 return "" 475 return ""
@@ -529,7 +527,7 @@ final class ODTRenderer {
529 let parentLow = heading.ancestors.last.flatMap { headings[$0]?.lowLevel } ?? false 527 let parentLow = heading.ancestors.last.flatMap { headings[$0]?.lowLevel } ?? false
530 out += "\n<text:list text:style-name=\"\(style)\" text:continue-numbering=\"\(parentLow)\">" 528 out += "\n<text:list text:style-name=\"\(style)\" text:continue-numbering=\"\(parentLow)\">"
531 } 529 }
532 frames.append(Frame(style: style)) 530 frames.append(Frame(style: style, heading: true))
533 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() : "") 531 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() : "")
534 let frame = frames.removeLast() 532 let frame = frames.removeLast()
535 out += "\n<text:list-item>\n\(body)\n\(frame.header ? "</text:list-header>" : "</text:list-item>")" 533 out += "\n<text:list-item>\n\(body)\n\(frame.header ? "</text:list-header>" : "</text:list-item>")"
@@ -596,9 +594,11 @@ final class ODTRenderer {
596 594
597 // MARK: - Lists 595 // MARK: - Lists
598 596
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`.
600 private struct Frame { 599 private struct Frame {
601 var style: String 600 var style: String
601 var heading = false
602 var header = false 602 var header = false
603 } 603 }
604 604
@@ -664,9 +664,14 @@ final class ODTRenderer {
664 return "<text:span text:style-name=\"OrgCode\">\(mark)</text:span>" 664 return "<text:span text:style-name=\"OrgCode\">\(mark)</text:span>"
665 } 665 }
666 666
667 /// `org-odt-table`'s list handling: the open lists closed, `inner` in an indented section, 667 /// `org-odt-table`'s list handling for `node`: the open lists closed, `inner` in an indented
668 /// the lists opened again, the innermost item as a header. 668 /// section, the lists opened again, the innermost item as a header.
669 private func reopening(_ inner: String?) -> String { 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 }
670 var closing: [String] = [] 675 var closing: [String] = []
671 for frame in frames.reversed() { 676 for frame in frames.reversed() {
672 closing.append(frame.header ? "</text:list-header>" : "</text:list-item>") 677 closing.append(frame.header ? "</text:list-header>" : "</text:list-item>")
@@ -790,7 +795,7 @@ final class ODTRenderer {
790 }.joined(separator: "\n") 795 }.joined(separator: "\n")
791 var out = caption.map { "\n<text:p text:style-name=\"Table\">\($0)</text:p>" } ?? "" 796 var out = caption.map { "\n<text:p text:style-name=\"Table\">\($0)</text:p>" } ?? ""
792 out += "\n<table:table table:style-name=\"\(style)\">" + columnSpecs + "\n" + body + "</table:table>" 797 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)
794 } 799 }
795 800
796 /// `org-odt-format-label` as a definition: a bookmark, then the category, sequence number 801 /// `org-odt-format-label` as a definition: a bookmark, then the category, sequence number
@@ -879,8 +884,7 @@ final class ODTRenderer {
879 884
880 /// `org-odt-do-format-code`: one paragraph per line, the last one styled apart. 885 /// `org-odt-do-format-code`: one paragraph per line, the last one styled apart.
881 private func code(_ lines: [String], refs: [Int: String] = [:], retain: Bool = false, loc: Int? = nil, emptyLast: Bool = false) -> String { 886 private func code(_ lines: [String], refs: [Int: String] = [:], retain: Bool = false, loc: Int? = nil, emptyLast: Bool = false) -> String {
882 var lines = lines 887 let lines = emptyLast ? lines + [""] : lines
883 if emptyLast { lines.append("") }
884 let out = lines.enumerated().map { index, line -> String in 888 let out = lines.enumerated().map { index, line -> String in
885 var text = line 889 var text = line
886 if let ref = refs[index + 1], retain { text += " (\(ref))" } 890 if let ref = refs[index + 1], retain { text += " (\(ref))" }
Sources/OrgstarMobile/ExportMenu.swift +1 −1
@@ -111,7 +111,7 @@ struct OrgExport: Transferable {
111 } 111 }
112 try content.write(to: url, atomically: true, encoding: .utf8) 112 try content.write(to: url, atomically: true, encoding: .utf8)
113 case .odt: 113 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())
115 .write(to: url, options: .atomic) 115 .write(to: url, options: .atomic)
116 case .icalendar: 116 case .icalendar:
117 try ICalendarFiles.export(self.text, path: path, settings: settings, options: OrgPreferences.icalendarOptions(), 117 try ICalendarFiles.export(self.text, path: path, settings: settings, options: OrgPreferences.icalendarOptions(),
Tests/OrgCoreTests/ODTExportTests.swift +1
@@ -490,6 +490,7 @@ struct ODTExportTests {
490 "#+ATTR_ODT: :style TableWithHeaderRowAndColumn\n| a |\n", 490 "#+ATTR_ODT: :style TableWithHeaderRowAndColumn\n| a |\n",
491 "Code src_python[:exports code]{1 + 1} here.\n", 491 "Code src_python[:exports code]{1 + 1} here.\n",
492 "#+DATE: 2024\n#+begin_annotation\nNote.\n#+end_annotation\n", 492 "#+DATE: 2024\n#+begin_annotation\nNote.\n#+end_annotation\n",
493 "- a quote\n #+begin_quote\n | q |\n #+end_quote\n",
493 ]) 494 ])
494 func refuses(_ text: String) { 495 func refuses(_ text: String) {
495 #expect(throws: ODTExport.Failure.self) { try ODTExport.document(text, path: "/tmp/doc.org") } 496 #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
252 252
253Export 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. 253Export 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.
254 254
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.
256- 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. 256- 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.
257- Footnotes are the word processor's own notes. A note referred to again shows its number. 257- Footnotes are the word processor's own notes. A note referred to again shows its number.
258- 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. 258- 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
261- =#+ODT:= lines, =#+BEGIN_EXPORT odt= blocks and =@@odt:...@@= snippets go in as they are. 261- =#+ODT:= lines, =#+BEGIN_EXPORT odt= blocks and =@@odt:...@@= snippets go in as they are.
262- The styles (=styles.xml=) are orgstar's own: A4 pages with 2 cm margins. =#+ODT_STYLES_FILE:= is not read. 262- The styles (=styles.xml=) are orgstar's own: A4 pages with 2 cm margins. =#+ODT_STYLES_FILE:= is not read.
263 263
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.
265 265
266* Markdown export 266* Markdown export
267 267