ochre-sdk 1.0.38 → 1.0.39

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.
@@ -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,
@@ -21,6 +21,9 @@ const MDX_RENDER_ELEMENTS = {
21
21
  italic: "em",
22
22
  underline: "u"
23
23
  };
24
+ function hasNewlineWhitespace(value) {
25
+ return value?.split(" ").includes("newline") === true;
26
+ }
24
27
  function isXMLRichTextLink(value) {
25
28
  return typeof value === "object" && value != null;
26
29
  }
@@ -68,7 +71,7 @@ function applyMDXRenderElements(contentString, options) {
68
71
  }
69
72
  function applyNewlineWhitespace(contentString, whitespace, rendering) {
70
73
  if (whitespace == null) return contentString;
71
- if (!whitespace.split(" ").includes("newline")) return contentString;
74
+ if (!hasNewlineWhitespace(whitespace)) return contentString;
72
75
  if (rendering === "rich") return contentString.trim() === "***" ? `${contentString}\n` : `<br />\n${contentString}`;
73
76
  return `\n${contentString}`;
74
77
  }
@@ -257,7 +260,7 @@ function parseNestedStringItems(items, contentItem, options) {
257
260
  let result = "";
258
261
  let rawMDXBlockStartIndex = null;
259
262
  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) {
263
+ 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
264
  if (rawMDXBlockStartIndex == null) {
262
265
  rawMDXBlockStartIndex = index;
263
266
  continue;
@@ -272,7 +275,7 @@ function parseNestedStringItems(items, contentItem, options) {
272
275
  rawMDXBlocks: options.rawMDXBlocks
273
276
  });
274
277
  }
275
- if (rawMDXBlock !== "" && !rawMDXBlock.endsWith("\n") && item.whitespace?.split(" ").includes("newline") === true) rawMDXBlock += "\n";
278
+ if (rawMDXBlock !== "" && !rawMDXBlock.endsWith("\n") && hasNewlineWhitespace(item.whitespace)) rawMDXBlock += "\n";
276
279
  if (options.rendering === "rich" && options.rawMDXBlocks != null) {
277
280
  const placeholder = `${RAW_MDX_BLOCK_PLACEHOLDER_PREFIX}${options.rawMDXBlocks.length}${RAW_MDX_BLOCK_PLACEHOLDER_SUFFIX}`;
278
281
  options.rawMDXBlocks.push(rawMDXBlock);
@@ -755,6 +755,7 @@ function parseWebElement(elementResource, options, context) {
755
755
  });
756
756
  return {
757
757
  uuid: elementResource.uuid,
758
+ language: elementResource.lang ?? null,
758
759
  type: "element",
759
760
  title,
760
761
  cssStyles,
@@ -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;
@@ -226,6 +226,7 @@ type WebTitle<T extends LanguageCodes = LanguageCodes> = {
226
226
  */
227
227
  type WebElement<T extends LanguageCodes = LanguageCodes> = {
228
228
  uuid: string;
229
+ language: string | null;
229
230
  type: "element";
230
231
  title: WebTitle<T>;
231
232
  cssStyles: {
@@ -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"))),
@@ -536,6 +536,7 @@ type XMLPropertyValue = XMLBaseItem & {
536
536
  };
537
537
  };
538
538
  type XMLResource = XMLBaseItem & {
539
+ lang?: string;
539
540
  type?: string;
540
541
  date?: Date | XMLString;
541
542
  href?: string;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ochre-sdk",
3
- "version": "1.0.38",
3
+ "version": "1.0.39",
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.12.4",
77
+ "@types/node": "^24.13.1",
78
78
  "bumpp": "^11.1.0",
79
79
  "eslint": "^10.4.1",
80
- "knip": "^6.15.0",
81
- "prettier": "^3.8.3",
82
- "tsdown": "^0.22.1",
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": "prettier --check .",
92
- "format:fix": "prettier --write --list-different .",
91
+ "format": "oxfmt --check",
92
+ "format:fix": "oxfmt",
93
93
  "check-types": "tsc --noEmit",
94
94
  "test": "vitest run",
95
95
  "release": "bumpp"