Repository navigation
v0.24.0 — cross-document OMath splice API
Adds WordDocument.spliceOMath(...) and spliceParagraphOMath(...) for verbatim copy of <m:oMath> XML blocks between paragraphs across two WordDocument instances. Unblocks thesis-rescue use cases (kiki830621/collaboration_guo_analysis#15 / #17) where 522 inline OMath blocks were lost during prior pipelines.
API
public enum OMathSplicePosition {
case atStart, atEnd
case afterText(_ anchor: String, instance: Int = 1, options: AnchorLookupOptions = AnchorLookupOptions())
case beforeText(_ anchor: String, instance: Int = 1, options: AnchorLookupOptions = AnchorLookupOptions())
}
public enum OMathSpliceRpRMode { case full, omathOnly, discard }
public enum OMathSpliceNamespacePolicy { case strict, lenient }
extension WordDocument {
public mutating func spliceOMath(
from: Paragraph, toBodyParagraphIndex: Int,
position: OMathSplicePosition, omathIndex: Int = 0,
rPrMode: OMathSpliceRpRMode = .full,
namespacePolicy: OMathSpliceNamespacePolicy = .lenient
) throws -> Int
public mutating func spliceParagraphOMath(
from: Paragraph, toBodyParagraphIndex: Int,
rPrMode: OMathSpliceRpRMode = .full,
namespacePolicy: OMathSpliceNamespacePolicy = .lenient
) throws -> Int
}Highlights
- Carrier preservation — source's
Run.rawXMLOMath stays inline, source'sunrecognizedChildrenOMath stays direct-child - Joint document-order index for
omathIndexviapositionfield - Mid-paragraph splice via anchor-Run split — does not touch the other 12 position-indexed paragraph carriers
- Lenient namespace policy default — accepts
mml:vsm:prefix mismatch with same URI per ECMA-376 xmlnsauto-injection on extraction — preserves namespace context lost by Foundation'sXMLElement.xmlString
Tests
- 14 new test cases in
OMathSpliceTests.swiftcovering all 8 spec requirements - Full suite: 871 tests, 0 failures, 1 pre-existing skip
Spec
Full spec at openspec/changes/cross-document-omath-splice/ (proposal / design / spec / tasks).
Closes
#57