Repository navigation
Expand file tree
/
Copy pathviewer.html
More file actions
526 lines (436 loc) · 22.8 KB
/
Copy pathviewer.html
File metadata and controls
526 lines (436 loc) · 22.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" translate="no" class="notranslate" lang="en">
<head>
<title>MANO - Transcription Viewer | TEI-XML Manuscript Visualization</title>
<meta name="keywords" content="transcription viewer, TEI-XML, manuscripts, digital humanities, editor, facsimile, MANO">
<meta name="description" content="View and edit TEI-XML manuscript transcriptions with synchronized text, code, and facsimile image panels.">
<meta charset="UTF-8"/>
<meta name="viewport" content="width=device-width, initial-scale=1.0 shrink-to-fit=no"/>
<meta name="google" content="notranslate"/>
<link rel="canonical" href="https://mano-project.github.io/viewer.html"/>
<link rel="icon" type="image/png" href="images/mano-logo_nuovoFont.png">
<link rel="alternate" hreflang="en" href="URL">
<meta property="og:type" content="website">
<meta property="og:title" content="MANO – Transcription Viewer">
<meta property="og:description" content="An interactive viewer for exploring TEI-XML manuscript transcriptions with text and facsimile alignment.">
<meta property="og:image" content="https://mano-project.github.io/images/mano-logo_nuovoFont.png">
<meta property="og:url" content="https://mano-project.github.io/viewer.html">
<script type="application/ld+json">
{
"@context": "https://schema.org",
"@type": "WebApplication",
"name": "MANO – Transcription Viewer",
"url": "https://mano-project.github.io/viewer.html",
"applicationCategory": "Digital Humanities Tool",
"description": "A browser-based viewer for exploring TEI-XML transcriptions alongside facsimile images with live preview and editing capabilities.",
"creator": {
"@type": "Person",
"name": "Michela Parma",
"affiliation": "University of Mainz"
}
"inLanguage": "en"
}
</script>
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/css/bootstrap.min.css" rel="stylesheet">
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/js/bootstrap.bundle.min.js"></script>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.11.3/font/bootstrap-icons.css">
<link rel="stylesheet" type="text/css" href="css/style.css" media="screen"/>
<link rel="stylesheet" type="text/css" href="css/transcription-style.css" media="screen"/>
<!-- CodeMirror -->
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/codemirror@5.65.16/lib/codemirror.css">
<script src="https://cdn.jsdelivr.net/npm/codemirror@5.65.16/lib/codemirror.js"></script>
<script src="https://cdn.jsdelivr.net/npm/codemirror@5.65.16/mode/xml/xml.js"></script>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/codemirror@5.65.16/addon/fold/foldgutter.css">
<script src="https://cdn.jsdelivr.net/npm/codemirror@5.65.16/addon/fold/foldcode.js"></script>
<script src="https://cdn.jsdelivr.net/npm/codemirror@5.65.16/addon/fold/foldgutter.js"></script>
<script src="https://cdn.jsdelivr.net/npm/codemirror@5.65.16/addon/fold/xml-fold.js"></script>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.5.0/css/all.min.css">
<style>
.CodeMirror {
height: 500px;
background-color: #f8f9fa;
border: 1px solid #ccc;
border-radius: 0.5rem;
font-size: 11px;
}
</style>
</head>
<body>
<nav class="navbar bg-body-tertiary ">
<div class="container-fluid d-flex justify-content-between align-items-center position-relative py-2">
<!-- Invisible spacer to balance layout -->
<div style="width: 80px;"></div>
<!-- Centered logo -->
<div class="position-absolute start-50 translate-middle-x text-center">
<a class="navbar-brand" href="index.html">
<img src="images/mano-logo_nuovoFont.png" alt="MANO project logo" width="65" class="d-inline-block align-text-top">
</a>
</div>
<!-- Offcanvas toggle aligned right -->
<button class="navbar-toggler" type="button" data-bs-toggle="offcanvas" data-bs-target="#offcanvasNavbar"
aria-controls="offcanvasNavbar" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div class="offcanvas offcanvas-end" tabindex="-1" id="offcanvasNavbar" aria-labelledby="offcanvasNavbarLabel">
<div class="offcanvas-header">
<h5 class="offcanvas-title" id="offcanvasNavbarLabel"><MANO></h5>
<button type="button" class="btn-close" data-bs-dismiss="offcanvas" aria-label="Close"></button>
</div>
<div class="offcanvas-body">
<ul class="navbar-nav justify-content-end flex-grow-1 pe-3">
<li class="nav-item"><a class="nav-link" href="index.html">Home</a></li>
<li class="nav-item"><a class="nav-link" href="resources.html">Resources</a></li>
<li class="nav-item"><a class="nav-link" href="editor.html">Metadata Editor</a></li>
<li class="nav-item"><a class="nav-link" href="collection.html">Metadata Collection</a></li>
<li class="nav-item"><a class="nav-link active" href="viewer.html">Transcription Viewer</a></li>
<li class="nav-item"><a class="nav-link" href="documentation.html">Documentation</a></li>
<li class="nav-item"><a class="nav-link" href="about.html">About</a></li>
</ul>
</div>
</div>
</div>
</nav>
<div class="container mt-4 mb-3">
<button onclick="history.back()" class="btn back-btn btn-sm btn-outline-secondary" aria-label="Go back">Back</button>
<h1 class="page-title">Transcription Viewer</h1>
<div class="row align-items-end mt-4">
<!-- Button column -->
<div class="col-12 col-md-4 d-flex justify-content-start mb-2 mb-md-0">
<button type="button" class="btn btn-primary responsive-btn" data-bs-toggle="modal" data-bs-target="#infoTranscriptionViewer" aria-label="Open About Transcription Viewer">
<i class="bi bi-info-circle"></i> About
</button>
</div>
<div class="col-12 col-md-4 text-start text-md-center mb-2 mb-md-0">
<label for="xmlFileInput" class="form-label">Upload TEI-XML transcription</label>
<input class="form-control" type="file" id="xmlFileInput" accept=".xml">
</div>
<div class="col-12 col-md-4 d-flex justify-content-start justify-content-md-end">
<button type="button" class="btn btn-outline-secondary responsive-btn"
onclick="window.location.href='converter.html'" aria-label="Go to Convert PAGE-XML into TEI-XML">
Convert PAGE-XML into TEI-XML
</button>
</div>
</div>
<div class="mt-3 mb-5 d-flex justify-content-center gap-2">
<button id="loadSampleBtn" class="btn btn-secondary btn-sm" type="button">
<i class="bi bi-file-earmark-text"></i> Load sample
</button>
<button id="clearAllBtn" class="btn btn-danger btn-sm" type="button">
<i class="bi bi-x-circle"></i> Clear all
</button>
</div>
<!-- About Transcription Viewer Modal -->
<div class="modal fade" id="infoTranscriptionViewer" tabindex="-1" aria-labelledby="infoTranscriptionViewerLabel" aria-hidden="true">
<div class="modal-dialog modal-lg">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="infoTranscriptionViewerLabel">About Transcription Viewer</h5>
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
</div>
<div class="modal-body">
<span>The Transcription Viewer allows the upload of manuscript transcriptions created with external tools in XML format. Once loaded, the transcription is displayed in three synchronized views: the <strong>raw XML code</strong>, a <strong>rendered text</strong> version with basic styling, and - when available - <strong>digitized manuscript images</strong> aligned with the transcription. This setup enables a combined view of structure, content, and original manuscript facsimiles.</span>
<br/>
<br/>
<span>The <strong>Load sample</strong> function provides a ready-made TEI-XML transcription that users can explore, allowing them to understand how the viewer handles pagination, rendering, and image alignment before uploading their own data.</span>
<br/>
<br/>
<span>The XML can be modified directly within the editor panel. By clicking <strong>Update Preview</strong>, the visual rendering and image alignment are refreshed to reflect the changes. The updated transcription may then be downloaded as a new XML file for further use.</span>
<br/>
<br/>
<span>When a single transcription file in TEI-XML is not available but multiple PAGE-XML files are provided, the <strong>Convert PAGE-XML into TEI-XML</strong> button can be used. A dedicated page is opened where the PAGE-XML files may be uploaded and merged into one combined TEI-XML file. Once generated and downloaded, the unified file can then be uploaded into the Transcription Viewer for visualization and further editing.
</span>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal" aria-label="Close">Close</button>
</div>
</div>
</div>
</div>
<div id="pageNav" class="text-center mb-3">
<button class="btn btn-outline-primary btn-sm" onclick="previousPage()" aria-label="Previous page">Previous page</button>
<select id="pageSelector" class="form-select form-select-sm d-inline-block w-auto mx-2" onchange="goToSelectedPage()">
<option></option>
</select>
<button class="btn btn-outline-primary btn-sm" onclick="nextPage()" aria-label="Next page">Next page</button>
</div>
<div class="row mb-4">
<div id="xmlColumn" class="col-12 col-lg-4 mb-5 mb-lg-0">
<label for="xmlEditor" class="form-label">XML</label>
<textarea id="xmlEditor"></textarea>
<button class="btn btn-primary btn-sm mt-2" onclick="renderXML()" aria-label="Update preview">Update preview</button>
<button class="btn btn-primary btn-sm mt-2" onclick="downloadXML()" aria-label="Download updated XML">Download updated XML</button>
</div>
<div id="visualColumn" class="col-12 col-lg-4 mb-5 mb-lg-0">
<label class="form-label">Transcription</label>
<div id="styledOutput" class="border"></div>
</div>
<div id="imageColumn" class="col-12 col-lg-4 mb-5 mb-lg-0">
<label class="form-label">Digitized Image</label>
<div id="imageWrapper" class="border" style="height: 500px; overflow: auto; position: relative;">
<img id="pageImage" src="" style="transform: scale(1); transform-origin: top left; display: block;">
</div>
<div class="mt-2 text-center">
<button class="btn btn-sm btn-outline-secondary" onclick="zoomImage(-0.1)" aria-label="Zoom out">−</button>
<button class="btn btn-sm btn-outline-secondary" onclick="zoomImage(0.1)" aria-label="Zoom in">+</button>
</div>
</div>
</div>
</div>
<footer class="footer bg-body-tertiary text-center py-4">
<div class="container">
<!-- Logo centered -->
<div class="mb-3">
<a class="navbar-brand" href="index.html">
<img src="images/mano-logo_nuovoFont.png" alt="MANO project logo" width="50">
</a>
</div>
<!-- Links centered in one line -->
<div class="mb-3">
<a class="footer-link mx-2" href="index.html">Home</a>
<a class="footer-link mx-2" href="resources.html">Resources</a>
<a class="footer-link mx-2" href="editor.html">Metadata Editor</a>
<a class="footer-link mx-2" href="collection.html">Metadata Collection</a>
<a class="footer-link mx-2" href="viewer.html">Transcription Viewer</a>
<a class="footer-link mx-2" href="documentation.html">Documentation</a>
<a class="footer-link mx-2" href="about.html">About</a>
</div>
<!-- Copyright centered -->
<div class="text-center mt-2">
<span>© 2025 <span class="mano"><MANO></span></span>
</div>
</div>
</footer>
<div class="py-1 text-center">
<small>
<span class="m-1">
<a href="imprint.html" style="color: black!important">Imprint & Privacy</a>
</span> |
<span class="m-1">
<a href="https://github.com/orgs/mano-project/repositories" target="_blank" style="color: black!important"><i class="fa-brands fa-github"></i> GitHub Repositories</a>
</span> |
<span class="m-1">
<a href="https://creativecommons.org/licenses/by-nc-sa/4.0/" target="_blank" style="color: black!important">CC BY-NC-SA 4.0</a><img src="https://mirrors.creativecommons.org/presskit/icons/cc.svg" alt="Creative Commons" style="max-width: 1em;max-height:1em;margin-left: .2em;"><img src="https://mirrors.creativecommons.org/presskit/icons/by.svg" alt="Attribution" style="max-width: 1em;max-height:1em;margin-left: .2em;"><img src="https://mirrors.creativecommons.org/presskit/icons/nc.svg" alt="Non Commercial" style="max-width: 1em;max-height:1em;margin-left: .2em;"><img src="https://mirrors.creativecommons.org/presskit/icons/sa.svg" alt="Share Alike" style="max-width: 1em;max-height:1em;margin-left: .2em;">
</span>
</small>
</div>
<script>
let pages = [];
let currentPageIndex = 0;
function renderXML() {
const xml = codeMirrorEditor.getValue();
const parser = new DOMParser();
const xmlDoc = parser.parseFromString(xml, "application/xml");
const ns = "http://www.tei-c.org/ns/1.0";
const textBody = xmlDoc.getElementsByTagNameNS(ns, "text")[0];
if (!textBody) return alert("No <text> element found");
const allPBs = xmlDoc.getElementsByTagNameNS(ns, "pb");
pages = [];
let containsFacs = false;
const styledOutput = document.getElementById("styledOutput");
const pageSelector = document.getElementById("pageSelector"); // ⬅️ added
if (allPBs.length === 0) {
// Fallback: no <pb>, render full text normally
const html = serializeTEI(textBody);
styledOutput.innerHTML = html;
pages.push({ facs: "" }); // One blank facs entry to support displayPage()
// Clear selector if exists
if (pageSelector) {
pageSelector.innerHTML = "<option></option>";
}
} else {
let pbIndex = 0;
const clonedText = textBody.cloneNode(true);
const pbNodes = clonedText.getElementsByTagNameNS(ns, "pb");
if (pageSelector) pageSelector.innerHTML = ""; // ⬅️ reset selector
let fallbackCount = 1;
for (let pb of Array.from(pbNodes)) {
const facs = pb.getAttribute("facs") || "";
if (facs.trim()) containsFacs = true;
const anchor = document.createElement("span");
anchor.id = `pb-${pbIndex}`;
pb.parentNode.insertBefore(anchor, pb);
pages.push({ facs });
// Add option to <select>
if (pageSelector) {
const n = pb.getAttribute("n");
const label = n ? `${n}` : `${fallbackCount++}`;
const option = document.createElement("option");
option.value = pbIndex;
option.textContent = label;
pageSelector.appendChild(option);
}
pbIndex++;
}
const html = serializeTEI(clonedText);
styledOutput.innerHTML = html;
}
// Responsive layout updates
const imageCol = document.getElementById("imageColumn");
const xmlCol = document.getElementById("xmlColumn");
const visualCol = document.getElementById("visualColumn");
const nav = document.getElementById("pageNav");
if (!containsFacs && allPBs.length === 0) {
imageCol.style.display = "none";
nav.style.display = "none";
xmlCol.classList.replace("col-lg-4", "col-lg-6");
visualCol.classList.replace("col-lg-4", "col-lg-6");
} else {
imageCol.style.display = containsFacs ? "block" : "none";
nav.style.display = "block";
xmlCol.classList.replace("col-lg-6", "col-lg-4");
visualCol.classList.replace("col-lg-6", "col-lg-4");
}
currentPageIndex = 0;
displayPage();
}
//Convert XML to HTML
function serializeTEI(node) {
const clone = node.cloneNode(true);
const xs = new XMLSerializer();
return xs.serializeToString(clone)
.replace(/xmlns(:\w+)?="[^"]+"/g, "") // Remove xmlns declarations
.replace(/<([\/]?)tei:/g, "<$1"); // Remove tei: prefix
}
function extractTextWithLB(node) {
let result = "";
function walk(n) {
if (n.nodeType === 3) {
result += n.textContent;
} else if (n.nodeType === 1) {
if (n.localName === "lb") {
result += "\n";
}
Array.from(n.childNodes).forEach(walk);
}
}
walk(node);
return result;
}
function goToSelectedPage() {
const selector = document.getElementById("pageSelector");
if (selector) {
currentPageIndex = parseInt(selector.value);
displayPage(currentPageIndex);
}
}
function nextPage() {
if (currentPageIndex < pages.length - 1) {
currentPageIndex++;
displayPage();
}
}
function previousPage() {
if (currentPageIndex > 0) {
currentPageIndex--;
displayPage();
}
}
function displayPage() {
const current = pages[currentPageIndex];
// Update image
const imageElement = document.getElementById("pageImage");
imageElement.src = current?.facs || "";
imageElement.style.display = current?.facs ? "block" : "none";
// Scroll visual transcription
const targetId = `pb-${currentPageIndex}`;
const targetElement = document.getElementById(targetId);
if (targetElement) {
targetElement.scrollIntoView({ behavior: "smooth", block: "start" });
}
//Scroll to <pb> in CodeMirror
const xmlContent = codeMirrorEditor.getValue();
const lines = xmlContent.split("\n");
const targetLine = lines.findIndex(line =>
line.includes("<pb") && line.includes(`facs`) &&
(lines.filter(l => l.includes("<pb")).indexOf(line) === currentPageIndex)
);
if (targetLine !== -1) {
codeMirrorEditor.setCursor({ line: targetLine, ch: 0 });
// Align line to top
const topOffset = codeMirrorEditor.charCoords({ line: targetLine, ch: 0 }, "local").top;
codeMirrorEditor.scrollTo(null, topOffset);
}
// Prev ad Next actions reflected in the page number visualiser
const selector = document.getElementById("pageSelector");
if (selector) selector.value = currentPageIndex;
}
const fileInput = document.getElementById("xmlFileInput");
fileInput.addEventListener("change", function () {
const file = this.files[0];
const reader = new FileReader();
reader.onload = function (e) {
codeMirrorEditor.setValue(e.target.result);
renderXML();
};
reader.readAsText(file);
});
//Download Updated XML button
function downloadXML() {
const xmlContent = codeMirrorEditor.getValue(); // get updated XML from CodeMirror
const blob = new Blob([xmlContent], { type: "application/xml" });
const url = URL.createObjectURL(blob);
const a = document.createElement("a");
a.href = url;
a.download = "updated-transcription.xml";
document.body.appendChild(a);
a.click();
document.body.removeChild(a);
URL.revokeObjectURL(url);
}
// Initialize CodeMirror (XML visualiser)
const codeMirrorEditor = CodeMirror.fromTextArea(document.getElementById("xmlEditor"), {
mode: "application/xml",
lineNumbers: true,
lineWrapping: true,
tabSize: 2,
theme: "default",
foldGutter: true,
gutters: ["CodeMirror-linenumbers", "CodeMirror-foldgutter"]
});
//Image Zoom in ad Zoom out
let currentZoom = 1;
function zoomImage(delta) {
const img = document.getElementById("pageImage");
currentZoom = Math.max(0.2, Math.min(4, currentZoom + delta)); // Limit zoom range
img.style.transform = `scale(${currentZoom})`;
}
// --- Load Sample Button (TEI-XML version) ---
document.getElementById("loadSampleBtn")?.addEventListener("click", async () => {
try {
const response = await fetch("test/test-transcription/bamberg-sb-c-6-06.xml");
if (!response.ok) throw new Error("Failed to load sample XML");
const xmlText = await response.text();
// Simulate file upload so existing logic is reused
const sampleFile = new File([xmlText], "bamberg-sb-c-6-06.xml", { type: "application/xml" });
const fileInput = document.getElementById("xmlFileInput");
// Clear current editor and page content
codeMirrorEditor.setValue("");
document.getElementById("styledOutput").innerHTML = "";
document.getElementById("pageImage").src = "";
const dataTransfer = new DataTransfer();
dataTransfer.items.add(sampleFile);
fileInput.files = dataTransfer.files;
// Trigger the same file upload logic already defined
fileInput.dispatchEvent(new Event("change", { bubbles: true }));
} catch (error) {
alert("Could not load sample XML: " + error.message);
}
});
// --- Clear All Button ---
document.getElementById("clearAllBtn")?.addEventListener("click", () => {
if (confirm("This will clear the loaded transcription. Proceed?")) {
// Clear editor content
codeMirrorEditor.setValue("");
// Clear preview panels
document.getElementById("styledOutput").innerHTML = "";
document.getElementById("pageImage").src = "";
document.getElementById("pageSelector").innerHTML = "<option></option>";
// Reset pages array
pages = [];
currentPageIndex = 0;
}
});
</script>
<script src="JS/adjustButtonSize.js"></script>
</body>
</html>