Skip to content

v0.24.0 — cross-document OMath splice API

Choose a tag to compare

@kiki830621 kiki830621 released this 04 May 07:04
· 313 commits to main since this release

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.rawXML OMath stays inline, source's unrecognizedChildren OMath stays direct-child
  • Joint document-order index for omathIndex via position field
  • Mid-paragraph splice via anchor-Run split — does not touch the other 12 position-indexed paragraph carriers
  • Lenient namespace policy default — accepts mml: vs m: prefix mismatch with same URI per ECMA-376
  • xmlns auto-injection on extraction — preserves namespace context lost by Foundation's XMLElement.xmlString

Tests

  • 14 new test cases in OMathSpliceTests.swift covering 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