Skip to content

Latest commit

 

History

5 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 

Repository files navigation

XMLUtilities, as used in gnorium.com

A Swift package for reading XML documents — TEI transcriptions in particular — as the pages and lines a reader sees.

Overview

XMLUtilities is the counterpart of markdown-utilities. Where MarkdownRenderer turns a source format into an HTML fragment, TEIRenderer turns a TEI document into the pages a view draws: a facsimile edition is read one opening at a time, and no HTML fragment can carry that structure.

Features

  • TEIRenderer: splits a document into pages at the page breaks that carry a facsimile, and reads each page as typed lines (text, heading, speaker, stage direction, page-turn mark).
  • XMLFormatter: XML as syntax with no knowledge of any vocabulary — pretty-printing, single-attribute reads, entity decoding, body extraction.
  • Line breaks are kept: a diplomatic transcript says where the compositor broke the line, so <lb/> ends a line rather than collapsing into a space.

Two kinds of page break

A source that photographs openings writes two kinds of <pb>:

<pb n="A1 verso – A2 recto" facs="https://…/iiif/8/full/max/0/default.jpg"/>
<pb n="A1v"/>

The first is a facsimile — one image, one page. The second is a side of the leaf, and becomes a mark on the page it falls in. Counting both makes a 64-image quarto read as 162 pages.

Installation

Swift Package Manager

Add XMLUtilities to your Package.swift:

dependencies: [
    .package(url: "https://github.com/gnorium/xml-utilities.git", branch: "main")
]

Then add it to your target dependencies:

.target(
    name: "YourTarget",
    dependencies: [
        .product(name: "XMLUtilities", package: "xml-utilities")
    ]
)

Requirements

  • Swift 6.2+

Usage

import XMLUtilities

for page in TEIRenderer.pages(in: tei) {
    print(page.label)          // "A1 verso – A2 recto"
    print(page.facsimileURL)   // the image it was transcribed from
    for line in page.lines where line.kind == .speaker {
        print(line.text)
    }
}

let readable = XMLFormatter.prettified(page.markup)

Everything is #if SERVER; the module compiles to an empty one under Embedded Swift for WASI, so a package shared by server and client can depend on it unconditionally.

License

Apache License 2.0 - See LICENSE for details

Contributing

Contributions welcome! Please open an issue or submit a pull request.

Related Packages

About

XMLUtilities, as used in gnorium.com

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages