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.
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.
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.
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.
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")
]
)- Swift 6.2+
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.
Apache License 2.0 - See LICENSE for details
Contributions welcome! Please open an issue or submit a pull request.
- markdown-utilities - Markdown to HTML with media attribution syntax
- design-tokens - Universal design tokens based on Apple HIG
- diff-engine - Platform-agnostic character-level diff engine
- embedded-swift-utilities - Utility functions for Embedded Swift environments
- artifact-core - IIIF Presentation API v3 types + deep zoom viewer
- admin-core - Core admin functionalities for web applications
- web-apis - Web API implementations for Swift WebAssembly
- web-builders - HTML, CSS, JS, and SVG DSL builders
- web-components - Reusable UI components for web applications
- web-formats - Structured data format builders
- web-security - Portable security utilities for web applications
- web-types - Shared web types for web applications