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.
@@ -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,
@@ -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.split(" ").includes("newline")) return contentString;
72
- if (rendering === "rich") return contentString.trim() === "***" ? `${contentString}\n` : `<br />\n${contentString}`;
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?.split(" ").includes("newline") === true) rawMDXBlock += "\n";
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
- result += parseXMLStringItem(item, contentItem, options);
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];
@@ -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.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.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"