ochre-sdk 1.0.43 → 1.0.45

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.
@@ -69,10 +69,6 @@ function applyMDXRenderElements(contentString, options) {
69
69
  function applyNewlineWhitespace(contentString, whitespace, rendering) {
70
70
  if (whitespace == null) return contentString;
71
71
  if (!whitespace.split(" ").includes("newline")) return contentString;
72
- if (contentString === "") {
73
- if (rendering === "rich") return "<br />\n<br />\n";
74
- return "\n\n";
75
- }
76
72
  if (rendering === "rich") return contentString.trim() === "***" ? `${contentString}\n` : `<br />\n${contentString}`;
77
73
  return `\n${contentString}`;
78
74
  }
@@ -245,7 +241,14 @@ function hasRichTextEnvelope(item) {
245
241
  return item.properties?.property[0] != null || getXMLRichTextLinks(item).length > 0;
246
242
  }
247
243
  function parseXMLStringItem(item, contentItem, options) {
248
- if (!(item.payload != null || item.string != null) && getXMLRichTextLinks(item).length === 0) return applyNewlineWhitespace("", item.whitespace, options.rendering);
244
+ if (!(item.payload != null && item.payload !== "" || item.string != null) && getXMLRichTextLinks(item).length === 0) {
245
+ const hasNewlineWhitespace = item.whitespace?.split(" ").includes("newline") === true;
246
+ const nextHasNewlineWhitespace = options.nextItem?.whitespace?.split(" ").includes("newline") === true;
247
+ if (hasNewlineWhitespace && options.rendering === "plain") return nextHasNewlineWhitespace ? "\n" : "\n\n";
248
+ if (hasNewlineWhitespace && options.rendering === "rawMDX") return nextHasNewlineWhitespace ? "\n<br />" : "\n<br />\n";
249
+ if (hasNewlineWhitespace && options.rendering === "rich") return nextHasNewlineWhitespace ? "<br />\n" : "<br />\n<br />\n";
250
+ return applyNewlineWhitespace("", item.whitespace, options.rendering);
251
+ }
249
252
  if (hasRichTextEnvelope(item)) {
250
253
  let linkString = item.payload != null ? parseXMLStringPayload(item, { rendering: options.rendering }) : parseNestedStringItems(item.string ?? [], contentItem, { ...options });
251
254
  if (item.rend != null) linkString = parseRenderOptions(linkString, item.rend, options.rendering);
@@ -273,10 +276,10 @@ function parseNestedStringItems(items, contentItem, options) {
273
276
  if (rawItem != null) rawMDXBlock += parseXMLStringItem(rawItem, contentItem, {
274
277
  languages: options.languages,
275
278
  rendering: rawMDXBlockRendering,
276
- rawMDXBlocks: options.rawMDXBlocks
279
+ rawMDXBlocks: options.rawMDXBlocks,
280
+ nextItem: rawIndex + 1 < index ? items[rawIndex + 1] : void 0
277
281
  });
278
282
  }
279
- if (rawMDXBlock !== "" && !rawMDXBlock.endsWith("\n") && item.whitespace?.split(" ").includes("newline") === true) rawMDXBlock += "\n";
280
283
  if (options.rendering === "rich" && options.rawMDXBlocks != null) {
281
284
  const placeholder = `${RAW_MDX_BLOCK_PLACEHOLDER_PREFIX}${options.rawMDXBlocks.length}${RAW_MDX_BLOCK_PLACEHOLDER_SUFFIX}`;
282
285
  options.rawMDXBlocks.push(rawMDXBlock);
@@ -286,7 +289,10 @@ function parseNestedStringItems(items, contentItem, options) {
286
289
  continue;
287
290
  }
288
291
  if (rawMDXBlockStartIndex != null) continue;
289
- result += parseXMLStringItem(item, contentItem, options);
292
+ result += parseXMLStringItem(item, contentItem, {
293
+ ...options,
294
+ nextItem: items[index + 1]
295
+ });
290
296
  }
291
297
  if (rawMDXBlockStartIndex != null) for (let index = rawMDXBlockStartIndex; index < items.length; index += 1) {
292
298
  const item = items[index];
@@ -806,10 +806,12 @@ function parseWebpage(webpageResource, options, context, slugPrefix) {
806
806
  const webpageResources = webpageResource.resource != null ? normalizeWebsiteResources(webpageResource.resource) : [];
807
807
  const items = [];
808
808
  for (const resource of webpageResources) {
809
- const resourceType = websitePresentationReader(resource.properties != null ? parseSimplifiedProperties(resource.properties, options) : []).value("presentation");
809
+ const resourceProperties = resource.properties != null ? parseSimplifiedProperties(resource.properties, options) : [];
810
+ const resourceType = websitePresentationReader(resourceProperties).value("presentation");
810
811
  if (resourceType === null) continue;
811
812
  switch (resourceType) {
812
813
  case "element": {
814
+ if (websitePresentationReader(resourceProperties).nestedByValue("presentation", "element").value("component") === "sidebar") continue;
813
815
  const element = parseWebElement(resource, options, context);
814
816
  items.push(element);
815
817
  break;
@@ -969,6 +971,7 @@ function parseWebBlock(blockResource, options, context) {
969
971
  const blockProperties = blockResource.properties ? parseSimplifiedProperties(blockResource.properties, options) : [];
970
972
  const returnBlock = {
971
973
  uuid: blockResource.uuid,
974
+ language: blockResource.lang ?? null,
972
975
  type: "block",
973
976
  title: parseWebTitle(blockProperties, parseIdentification(blockResource.identification, options)),
974
977
  items: [],
@@ -477,6 +477,7 @@ type WebAccordionItem<T extends LanguageCodes = LanguageCodes> = {
477
477
  */
478
478
  type WebBlock<T extends LanguageCodes = LanguageCodes, U extends WebBlockLayout = WebBlockLayout> = {
479
479
  uuid: string;
480
+ language: string | null;
480
481
  type: "block";
481
482
  title: WebTitle<T>;
482
483
  items: U extends "accordion" ? Array<WebAccordionItem<T> | WebBlockItem<T>> : Array<WebBlockItem<T>>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ochre-sdk",
3
- "version": "1.0.43",
3
+ "version": "1.0.45",
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",