ochre-sdk 1.0.38 → 1.0.40
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/parsers/index.mjs
CHANGED
|
@@ -1137,6 +1137,7 @@ function parseResource(rawResource, options) {
|
|
|
1137
1137
|
for (const resource of rawResource.resource ?? []) items.push(parseResource(resource, options));
|
|
1138
1138
|
return {
|
|
1139
1139
|
...parseBaseItem("resource", rawResource, options),
|
|
1140
|
+
language: rawResource.lang ?? null,
|
|
1140
1141
|
type: rawResource.type ?? "",
|
|
1141
1142
|
href: parseHref(rawResource.href),
|
|
1142
1143
|
fileFormat: rawResource.fileFormat ?? null,
|
package/dist/parsers/string.mjs
CHANGED
|
@@ -15,12 +15,17 @@ const HEADING_LEVEL_TOKEN = "heading-level";
|
|
|
15
15
|
const RAW_MDX_BLOCK_DELIMITER = "``md``";
|
|
16
16
|
const RAW_MDX_BLOCK_PLACEHOLDER_PREFIX = "\0raw-mdx-block:";
|
|
17
17
|
const RAW_MDX_BLOCK_PLACEHOLDER_SUFFIX = "\0";
|
|
18
|
+
const RICH_LINE_BREAK = "<br />\n";
|
|
19
|
+
const RICH_PARAGRAPH_BREAK = "\n\n";
|
|
18
20
|
const MDX_QUOTED_ATTRIBUTE_ESCAPE_REGEX = /[\n\r"]/;
|
|
19
21
|
const MDX_RENDER_ELEMENTS = {
|
|
20
22
|
bold: "strong",
|
|
21
23
|
italic: "em",
|
|
22
24
|
underline: "u"
|
|
23
25
|
};
|
|
26
|
+
function hasNewlineWhitespace(value) {
|
|
27
|
+
return value?.split(" ").includes("newline") === true;
|
|
28
|
+
}
|
|
24
29
|
function isXMLRichTextLink(value) {
|
|
25
30
|
return typeof value === "object" && value != null;
|
|
26
31
|
}
|
|
@@ -68,8 +73,9 @@ function applyMDXRenderElements(contentString, options) {
|
|
|
68
73
|
}
|
|
69
74
|
function applyNewlineWhitespace(contentString, whitespace, rendering) {
|
|
70
75
|
if (whitespace == null) return contentString;
|
|
71
|
-
if (!whitespace
|
|
72
|
-
if (
|
|
76
|
+
if (!hasNewlineWhitespace(whitespace)) return contentString;
|
|
77
|
+
if (contentString === "" && rendering !== "plain") return RICH_PARAGRAPH_BREAK;
|
|
78
|
+
if (rendering === "rich") return contentString.trim() === "***" ? `${contentString}\n` : `${RICH_LINE_BREAK}${contentString}`;
|
|
73
79
|
return `\n${contentString}`;
|
|
74
80
|
}
|
|
75
81
|
/**
|
|
@@ -257,7 +263,7 @@ function parseNestedStringItems(items, contentItem, options) {
|
|
|
257
263
|
let result = "";
|
|
258
264
|
let rawMDXBlockStartIndex = null;
|
|
259
265
|
for (const [index, item] of items.entries()) {
|
|
260
|
-
if (item.payload === RAW_MDX_BLOCK_DELIMITER && item.rend == null && item.links == null && item.properties == null && item.annotation == null && item.string == null) {
|
|
266
|
+
if (item.payload === RAW_MDX_BLOCK_DELIMITER && (index === 0 || hasNewlineWhitespace(item.whitespace)) && item.rend == null && item.links == null && item.properties == null && item.annotation == null && item.string == null) {
|
|
261
267
|
if (rawMDXBlockStartIndex == null) {
|
|
262
268
|
rawMDXBlockStartIndex = index;
|
|
263
269
|
continue;
|
|
@@ -272,7 +278,7 @@ function parseNestedStringItems(items, contentItem, options) {
|
|
|
272
278
|
rawMDXBlocks: options.rawMDXBlocks
|
|
273
279
|
});
|
|
274
280
|
}
|
|
275
|
-
if (rawMDXBlock !== "" && !rawMDXBlock.endsWith("\n") && item.whitespace
|
|
281
|
+
if (rawMDXBlock !== "" && !rawMDXBlock.endsWith("\n") && hasNewlineWhitespace(item.whitespace)) rawMDXBlock += "\n";
|
|
276
282
|
if (options.rendering === "rich" && options.rawMDXBlocks != null) {
|
|
277
283
|
const placeholder = `${RAW_MDX_BLOCK_PLACEHOLDER_PREFIX}${options.rawMDXBlocks.length}${RAW_MDX_BLOCK_PLACEHOLDER_SUFFIX}`;
|
|
278
284
|
options.rawMDXBlocks.push(rawMDXBlock);
|
|
@@ -282,7 +288,8 @@ function parseNestedStringItems(items, contentItem, options) {
|
|
|
282
288
|
continue;
|
|
283
289
|
}
|
|
284
290
|
if (rawMDXBlockStartIndex != null) continue;
|
|
285
|
-
|
|
291
|
+
const parsedItem = parseXMLStringItem(item, contentItem, options);
|
|
292
|
+
result += options.rendering === "rich" && result.endsWith("\n") && parsedItem.startsWith(RICH_LINE_BREAK) ? parsedItem.slice(6) : parsedItem;
|
|
286
293
|
}
|
|
287
294
|
if (rawMDXBlockStartIndex != null) for (let index = rawMDXBlockStartIndex; index < items.length; index += 1) {
|
|
288
295
|
const item = items[index];
|
package/dist/types/index.d.mts
CHANGED
|
@@ -655,6 +655,7 @@ type PropertyValue<T extends LanguageCodes = LanguageCodes, U extends ItemPayloa
|
|
|
655
655
|
* Resource in OCHRE
|
|
656
656
|
*/
|
|
657
657
|
type Resource<T extends LanguageCodes = LanguageCodes, U extends ItemPayloadKind = "topLevel"> = Prettify<BaseItem<"resource", T, U> & {
|
|
658
|
+
language: string | null;
|
|
658
659
|
type: string;
|
|
659
660
|
href: string | null;
|
|
660
661
|
fileFormat: string | null;
|
package/dist/types/website.d.mts
CHANGED
package/dist/xml/schemas.mjs
CHANGED
|
@@ -605,7 +605,8 @@ const XMLResource = v.object({
|
|
|
605
605
|
properties: v.optional(v.object({ property: v.array(XMLProperty) })),
|
|
606
606
|
bibliographies: v.optional(v.object({ bibliography: v.array(XMLBibliography) })),
|
|
607
607
|
resource: v.optional(v.array(v.lazy(() => XMLResource))),
|
|
608
|
-
view: v.optional(v.object({ resource: v.optional(v.array(v.lazy(() => XMLWebsiteResource))) }))
|
|
608
|
+
view: v.optional(v.object({ resource: v.optional(v.array(v.lazy(() => XMLWebsiteResource))) })),
|
|
609
|
+
lang: v.optional(v.string("XMLResource: lang is string and optional"))
|
|
609
610
|
}, "XMLResource: Shape error");
|
|
610
611
|
const XMLSection = v.object({
|
|
611
612
|
uuid: v.pipe(v.string("XMLSection: uuid is string and required"), v.check(isPseudoUuid, "XMLSection: uuid is not a valid pseudo-UUID")),
|
|
@@ -731,6 +732,7 @@ const XMLWebsiteResourceItem = v.lazy(() => v.union([
|
|
|
731
732
|
]));
|
|
732
733
|
const XMLWebsiteResource = v.lazy(() => v.object({
|
|
733
734
|
...XMLBaseItem.entries,
|
|
735
|
+
lang: v.optional(v.string("XMLWebsiteResource: lang is string and optional")),
|
|
734
736
|
type: v.optional(v.string("XMLWebsiteResource: type is string and optional")),
|
|
735
737
|
date: v.optional(v.union([customDateTime("XMLWebsiteResource: date is not a valid datetime"), XMLString])),
|
|
736
738
|
href: v.optional(v.pipe(v.string("XMLWebsiteResource: href is string and optional"), v.url("XMLWebsiteResource: href is not a valid URL"))),
|
package/dist/xml/types.d.mts
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "ochre-sdk",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.40",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"description": "Node.js library for working with OCHRE (Online Cultural and Historical Research Environment) data",
|
|
@@ -74,12 +74,12 @@
|
|
|
74
74
|
},
|
|
75
75
|
"devDependencies": {
|
|
76
76
|
"@antfu/eslint-config": "^9.0.0",
|
|
77
|
-
"@types/node": "^24.
|
|
77
|
+
"@types/node": "^24.13.1",
|
|
78
78
|
"bumpp": "^11.1.0",
|
|
79
79
|
"eslint": "^10.4.1",
|
|
80
|
-
"knip": "^6.
|
|
81
|
-
"
|
|
82
|
-
"tsdown": "^0.22.
|
|
80
|
+
"knip": "^6.16.1",
|
|
81
|
+
"oxfmt": "^0.53.0",
|
|
82
|
+
"tsdown": "^0.22.2",
|
|
83
83
|
"typescript": "^6.0.3",
|
|
84
84
|
"vitest": "^4.1.8"
|
|
85
85
|
},
|
|
@@ -88,8 +88,8 @@
|
|
|
88
88
|
"build": "tsdown",
|
|
89
89
|
"lint": "knip; eslint .",
|
|
90
90
|
"lint:fix": "knip --fix; eslint . --fix",
|
|
91
|
-
"format": "
|
|
92
|
-
"format:fix": "
|
|
91
|
+
"format": "oxfmt --check",
|
|
92
|
+
"format:fix": "oxfmt",
|
|
93
93
|
"check-types": "tsc --noEmit",
|
|
94
94
|
"test": "vitest run",
|
|
95
95
|
"release": "bumpp"
|