ochre-sdk 1.0.9 → 1.0.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.mjs +15 -67
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -758,11 +758,6 @@ const whitespaceSchema = v.pipe(v.string(), v.transform((str) => str.split(" "))
|
|
|
758
758
|
"leading"
|
|
759
759
|
])));
|
|
760
760
|
/**
|
|
761
|
-
* Schema for validating email addresses
|
|
762
|
-
* @internal
|
|
763
|
-
*/
|
|
764
|
-
const emailSchema = v.pipe(v.string(), v.email("Invalid email address"));
|
|
765
|
-
/**
|
|
766
761
|
* Schema for validating date data types
|
|
767
762
|
* @internal
|
|
768
763
|
*/
|
|
@@ -956,9 +951,6 @@ const ITEM_PAGE_TOKEN = "item-page";
|
|
|
956
951
|
const ENTRY_PAGE_TOKEN = "entry-page";
|
|
957
952
|
const VARIANT_TOKEN = "variant";
|
|
958
953
|
const HEADING_LEVEL_TOKEN = "heading-level";
|
|
959
|
-
const EMAIL_BRACKET_CLEANUP_REGEX = /(?<=\s|^)[([{]+|[)\]}]+(?=\s|$)/g;
|
|
960
|
-
const EMAIL_PUNCTUATION_CLEANUP_REGEX = /[!),:;?\]]/g;
|
|
961
|
-
const EMAIL_TRAILING_PERIOD_REGEX = /\.$/;
|
|
962
954
|
const MDX_QUOTED_ATTRIBUTE_ESCAPE_REGEX = /[\n\r"]/;
|
|
963
955
|
const MDX_RENDER_ELEMENTS = {
|
|
964
956
|
bold: "strong",
|
|
@@ -980,31 +972,6 @@ function transformPermanentIdentificationUrl(url) {
|
|
|
980
972
|
return url.replace("https://pi.lib.uchicago.edu/1001/org/ochre/", "https://ochre.lib.uchicago.edu/ochre/v2/ochre.php?uuid=");
|
|
981
973
|
}
|
|
982
974
|
/**
|
|
983
|
-
* Parses email addresses in a string into HTML links
|
|
984
|
-
*
|
|
985
|
-
* @param string - Input string to parse
|
|
986
|
-
* @returns String with emails converted to HTML links
|
|
987
|
-
*
|
|
988
|
-
* @internal
|
|
989
|
-
*/
|
|
990
|
-
function parseEmail(string) {
|
|
991
|
-
const splitString = string.split(" ");
|
|
992
|
-
const returnSplitString = [];
|
|
993
|
-
for (const string of splitString) {
|
|
994
|
-
const cleanString = transformPermanentIdentificationUrl(string).replaceAll(EMAIL_BRACKET_CLEANUP_REGEX, "").replaceAll(EMAIL_PUNCTUATION_CLEANUP_REGEX, "").replace(EMAIL_TRAILING_PERIOD_REGEX, "");
|
|
995
|
-
const index = string.indexOf(cleanString);
|
|
996
|
-
const { success } = v.safeParse(emailSchema, cleanString);
|
|
997
|
-
if (success) {
|
|
998
|
-
const before = index === -1 ? "" : string.slice(0, index);
|
|
999
|
-
const after = index === -1 ? "" : string.slice(index + cleanString.length);
|
|
1000
|
-
returnSplitString.push(`${before}<ExternalLink href="mailto:${cleanString}">${cleanString}</ExternalLink>${after}`);
|
|
1001
|
-
continue;
|
|
1002
|
-
}
|
|
1003
|
-
returnSplitString.push(string);
|
|
1004
|
-
}
|
|
1005
|
-
return returnSplitString.join(" ");
|
|
1006
|
-
}
|
|
1007
|
-
/**
|
|
1008
975
|
* Applies text rendering options (bold, italic, underline) to a string
|
|
1009
976
|
*
|
|
1010
977
|
* @param contentString - The string content to render
|
|
@@ -1069,7 +1036,6 @@ function parseWhitespace(contentString, whitespace, rendering) {
|
|
|
1069
1036
|
* @param string - XML string to parse
|
|
1070
1037
|
* @param options - Options for parsing
|
|
1071
1038
|
* @param options.rendering - Which text rendering to produce
|
|
1072
|
-
* @param options.parseEmail - Whether to parse email addresses
|
|
1073
1039
|
* @returns Formatted string with whitespace and rendering options
|
|
1074
1040
|
*
|
|
1075
1041
|
* @internal
|
|
@@ -1081,19 +1047,12 @@ function parseXMLStringVariant(string, options) {
|
|
|
1081
1047
|
return returnString;
|
|
1082
1048
|
}
|
|
1083
1049
|
function parseXMLStringPayload(string, options) {
|
|
1084
|
-
|
|
1085
|
-
return options.parseEmail ? parseEmail(returnString) : returnString;
|
|
1050
|
+
return (string.payload ?? "").replaceAll("<", options.rendering === "rich" ? String.raw`\<` : "<").replaceAll("{", String.raw`\{`).replaceAll("}", String.raw`\}`);
|
|
1086
1051
|
}
|
|
1087
|
-
function parseXMLString(string
|
|
1052
|
+
function parseXMLString(string) {
|
|
1088
1053
|
return {
|
|
1089
|
-
text: parseXMLStringVariant(string, {
|
|
1090
|
-
|
|
1091
|
-
parseEmail: false
|
|
1092
|
-
}),
|
|
1093
|
-
richText: parseXMLStringVariant(string, {
|
|
1094
|
-
rendering: "rich",
|
|
1095
|
-
parseEmail: options.parseEmail
|
|
1096
|
-
})
|
|
1054
|
+
text: parseXMLStringVariant(string, { rendering: "plain" }),
|
|
1055
|
+
richText: parseXMLStringVariant(string, { rendering: "rich" })
|
|
1097
1056
|
};
|
|
1098
1057
|
}
|
|
1099
1058
|
/**
|
|
@@ -1158,7 +1117,7 @@ function getFirstPropertyMetadata(item) {
|
|
|
1158
1117
|
}
|
|
1159
1118
|
function parseContentLikeForLanguage(value, options) {
|
|
1160
1119
|
if (value == null) return "";
|
|
1161
|
-
if (!("content" in value)) return parseXMLString(value
|
|
1120
|
+
if (!("content" in value)) return parseXMLString(value).text;
|
|
1162
1121
|
const contentItem = value.content.find((item) => item.lang === options.language) ?? value.content[0];
|
|
1163
1122
|
if (contentItem == null) return "";
|
|
1164
1123
|
const languages = [contentItem.lang];
|
|
@@ -1245,21 +1204,12 @@ function hasRichTextEnvelope(item) {
|
|
|
1245
1204
|
function parseXMLStringItem(item, contentItem, options) {
|
|
1246
1205
|
if (!(item.payload != null || item.string != null) && getXMLRichTextLinks(item).length === 0) return item.whitespace == null ? "" : parseWhitespace("", item.whitespace, options.rendering);
|
|
1247
1206
|
if (hasRichTextEnvelope(item)) {
|
|
1248
|
-
let linkString = item.payload != null ? parseXMLStringPayload(item, {
|
|
1249
|
-
rendering: options.rendering,
|
|
1250
|
-
parseEmail: false
|
|
1251
|
-
}) : parseNestedStringItems(item.string ?? [], contentItem, {
|
|
1252
|
-
...options,
|
|
1253
|
-
parseEmail: false
|
|
1254
|
-
});
|
|
1207
|
+
let linkString = item.payload != null ? parseXMLStringPayload(item, { rendering: options.rendering }) : parseNestedStringItems(item.string ?? [], contentItem, { ...options });
|
|
1255
1208
|
if (item.rend != null) linkString = parseRenderOptions(linkString, item.rend, options.rendering);
|
|
1256
1209
|
if (options.rendering === "plain") return applyWhitespaceToResult(linkString, item.whitespace, options.rendering);
|
|
1257
1210
|
return renderRichTextItem(item, linkString, contentItem, options);
|
|
1258
1211
|
}
|
|
1259
|
-
if (item.payload != null) return parseXMLStringVariant(item, {
|
|
1260
|
-
rendering: options.rendering,
|
|
1261
|
-
parseEmail: options.parseEmail
|
|
1262
|
-
});
|
|
1212
|
+
if (item.payload != null) return parseXMLStringVariant(item, { rendering: options.rendering });
|
|
1263
1213
|
let result = parseNestedStringItems(item.string ?? [], contentItem, options);
|
|
1264
1214
|
if (item.rend != null) result = parseRenderOptions(result, item.rend, options.rendering);
|
|
1265
1215
|
return applyWhitespaceToResult(result, item.whitespace, options.rendering);
|
|
@@ -1315,7 +1265,7 @@ function renderRichTextItem(item, linkString, contentItem, options) {
|
|
|
1315
1265
|
if (links.length === 0) return applyWhitespaceToResult(wrapWithTextStyling(linkString, annotationMetadata.textStyling), item.whitespace, rendering);
|
|
1316
1266
|
let result = "";
|
|
1317
1267
|
for (const link of links) {
|
|
1318
|
-
const linkContent = link.identification != null ? "content" in link.identification.label ? parseXMLContent(link.identification.label, { languages }) : MultilingualString.create(contentItem.lang, parseXMLString(link.identification.label
|
|
1268
|
+
const linkContent = link.identification != null ? "content" in link.identification.label ? parseXMLContent(link.identification.label, { languages }) : MultilingualString.create(contentItem.lang, parseXMLString(link.identification.label), languages) : MultilingualString.create(contentItem.lang, "", languages);
|
|
1319
1269
|
const contentText = (rendering === "rich" ? linkContent.getExactRichText(contentItem.lang) : linkContent.getExactText(contentItem.lang)) ?? "";
|
|
1320
1270
|
if ("type" in link && link.type != null) switch (link.type) {
|
|
1321
1271
|
case "IIIF":
|
|
@@ -1436,13 +1386,11 @@ function parseXMLContentItem(contentItem, options) {
|
|
|
1436
1386
|
return {
|
|
1437
1387
|
text: parseNestedStringItems(contentItem.string, contentItem, {
|
|
1438
1388
|
...options,
|
|
1439
|
-
rendering: "plain"
|
|
1440
|
-
parseEmail: false
|
|
1389
|
+
rendering: "plain"
|
|
1441
1390
|
}),
|
|
1442
1391
|
richText: parseNestedStringItems(contentItem.string, contentItem, {
|
|
1443
1392
|
...options,
|
|
1444
|
-
rendering: "rich"
|
|
1445
|
-
parseEmail: true
|
|
1393
|
+
rendering: "rich"
|
|
1446
1394
|
})
|
|
1447
1395
|
};
|
|
1448
1396
|
}
|
|
@@ -1481,10 +1429,10 @@ function parseLicense(availability) {
|
|
|
1481
1429
|
target: availability.license.target ?? null
|
|
1482
1430
|
};
|
|
1483
1431
|
}
|
|
1484
|
-
function parseStringLike(value
|
|
1432
|
+
function parseStringLike(value) {
|
|
1485
1433
|
if (value == null) return null;
|
|
1486
1434
|
if (typeof value === "string") return value;
|
|
1487
|
-
return parseXMLString(value
|
|
1435
|
+
return parseXMLString(value).text;
|
|
1488
1436
|
}
|
|
1489
1437
|
function isXMLContent(value) {
|
|
1490
1438
|
return "content" in value;
|
|
@@ -1497,7 +1445,7 @@ function multilingualFromText(text, options) {
|
|
|
1497
1445
|
function parseContentLike(value, options) {
|
|
1498
1446
|
if (value == null) return null;
|
|
1499
1447
|
if (typeof value === "string") return multilingualFromText(value, options);
|
|
1500
|
-
if (!isXMLContent(value)) return multilingualFromText(parseXMLString(value
|
|
1448
|
+
if (!isXMLContent(value)) return multilingualFromText(parseXMLString(value), options);
|
|
1501
1449
|
return parseXMLContent(value, { languages: options.languages });
|
|
1502
1450
|
}
|
|
1503
1451
|
function parseRequiredContentLike(value, options) {
|
|
@@ -1510,7 +1458,7 @@ function parseStringContent(value, options = FALLBACK_PARSER_OPTIONS) {
|
|
|
1510
1458
|
if (value == null) return "";
|
|
1511
1459
|
if (typeof value === "string") return value;
|
|
1512
1460
|
if (isXMLContent(value)) return parseXMLContent(value, { languages: options.languages }).getText();
|
|
1513
|
-
return parseXMLString(value
|
|
1461
|
+
return parseXMLString(value).text;
|
|
1514
1462
|
}
|
|
1515
1463
|
//#endregion
|
|
1516
1464
|
//#region src/parsers/index.ts
|
|
@@ -1943,7 +1891,7 @@ function parseImageMap(rawImageMap) {
|
|
|
1943
1891
|
function parseNote(rawNote, options) {
|
|
1944
1892
|
const authors = [];
|
|
1945
1893
|
for (const author of rawNote.authors?.author ?? []) authors.push(parsePerson(author, options));
|
|
1946
|
-
const content = rawNote.content == null ? multilingualFromText(parseXMLString(rawNote
|
|
1894
|
+
const content = rawNote.content == null ? multilingualFromText(parseXMLString(rawNote), options) : parseRequiredContentLike(rawNote, options);
|
|
1947
1895
|
return {
|
|
1948
1896
|
number: rawNote.noteNo ?? 0,
|
|
1949
1897
|
title: parseNoteTitle(rawNote, options),
|