ochre-sdk 1.0.43 → 1.0.44

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,7 +276,8 @@ 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
283
  if (rawMDXBlock !== "" && !rawMDXBlock.endsWith("\n") && item.whitespace?.split(" ").includes("newline") === true) rawMDXBlock += "\n";
@@ -286,7 +290,10 @@ function parseNestedStringItems(items, contentItem, options) {
286
290
  continue;
287
291
  }
288
292
  if (rawMDXBlockStartIndex != null) continue;
289
- result += parseXMLStringItem(item, contentItem, options);
293
+ result += parseXMLStringItem(item, contentItem, {
294
+ ...options,
295
+ nextItem: items[index + 1]
296
+ });
290
297
  }
291
298
  if (rawMDXBlockStartIndex != null) for (let index = rawMDXBlockStartIndex; index < items.length; index += 1) {
292
299
  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;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ochre-sdk",
3
- "version": "1.0.43",
3
+ "version": "1.0.44",
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",