ochre-sdk 1.0.15 → 1.0.16

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.
@@ -63,6 +63,12 @@ function applyMDXRenderElements(contentString, options) {
63
63
  }
64
64
  return result;
65
65
  }
66
+ function applyNewlineWhitespace(contentString, whitespace, rendering) {
67
+ if (whitespace == null) return contentString;
68
+ if (!whitespace.split(" ").includes("newline")) return contentString;
69
+ if (rendering === "rich") return contentString.trim() === "***" ? `${contentString}\n` : `<br />\n${contentString}`;
70
+ return `\n${contentString}`;
71
+ }
66
72
  /**
67
73
  * Parses XML string into a formatted string with rendering options
68
74
  *
@@ -76,7 +82,7 @@ function applyMDXRenderElements(contentString, options) {
76
82
  function parseXMLStringVariant(string, options) {
77
83
  let returnString = parseXMLStringPayload(string, options);
78
84
  if (string.rend != null) returnString = parseRenderOptions(returnString, string.rend, options.rendering);
79
- return returnString;
85
+ return applyNewlineWhitespace(returnString, string.whitespace, options.rendering);
80
86
  }
81
87
  function parseXMLStringPayload(string, options) {
82
88
  const payload = string.payload ?? "";
@@ -232,17 +238,17 @@ function hasRichTextEnvelope(item) {
232
238
  return item.properties?.property[0] != null || getXMLRichTextLinks(item).length > 0;
233
239
  }
234
240
  function parseXMLStringItem(item, contentItem, options) {
235
- if (!(item.payload != null || item.string != null) && getXMLRichTextLinks(item).length === 0) return "";
241
+ if (!(item.payload != null || item.string != null) && getXMLRichTextLinks(item).length === 0) return applyNewlineWhitespace("", item.whitespace, options.rendering);
236
242
  if (hasRichTextEnvelope(item)) {
237
243
  let linkString = item.payload != null ? parseXMLStringPayload(item, { rendering: options.rendering }) : parseNestedStringItems(item.string ?? [], contentItem, { ...options });
238
244
  if (item.rend != null) linkString = parseRenderOptions(linkString, item.rend, options.rendering);
239
- if (options.rendering === "plain") return linkString;
245
+ if (options.rendering === "plain") return applyNewlineWhitespace(linkString, item.whitespace, options.rendering);
240
246
  return renderRichTextItem(item, linkString, contentItem, options);
241
247
  }
242
248
  if (item.payload != null) return parseXMLStringVariant(item, { rendering: options.rendering });
243
249
  let result = parseNestedStringItems(item.string ?? [], contentItem, options);
244
250
  if (item.rend != null) result = parseRenderOptions(result, item.rend, options.rendering);
245
- return result;
251
+ return applyNewlineWhitespace(result, item.whitespace, options.rendering);
246
252
  }
247
253
  function parseNestedStringItems(items, contentItem, options) {
248
254
  let result = "";
@@ -292,7 +298,7 @@ function renderRichTextItem(item, linkString, contentItem, options) {
292
298
  const { languages, rendering } = options;
293
299
  const annotationMetadata = extractAnnotationMetadata(item, { language: contentItem.lang });
294
300
  const links = getXMLRichTextLinks(item);
295
- if (links.length === 0) return wrapWithTextStyling(linkString, annotationMetadata.textStyling);
301
+ if (links.length === 0) return applyNewlineWhitespace(wrapWithTextStyling(linkString, annotationMetadata.textStyling), item.whitespace, rendering);
296
302
  let result = "";
297
303
  for (const link of links) {
298
304
  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);
@@ -379,7 +385,7 @@ function renderRichTextItem(item, linkString, contentItem, options) {
379
385
  result += component;
380
386
  }
381
387
  }
382
- return result;
388
+ return applyNewlineWhitespace(result, item.whitespace, rendering);
383
389
  }
384
390
  /**
385
391
  * Parses rich text content into a formatted string with links and annotations
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ochre-sdk",
3
- "version": "1.0.15",
3
+ "version": "1.0.16",
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",