ochre-sdk 1.0.0-beta.11 → 1.0.0-beta.12

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.
Files changed (2) hide show
  1. package/dist/index.mjs +11 -6
  2. package/package.json +1 -1
package/dist/index.mjs CHANGED
@@ -805,6 +805,7 @@ const ITEM_PAGE_TOKEN = "item-page";
805
805
  const ENTRY_PAGE_TOKEN = "entry-page";
806
806
  const VARIANT_TOKEN = "variant";
807
807
  const HEADING_LEVEL_TOKEN = "heading-level";
808
+ const MDX_QUOTED_ATTRIBUTE_ESCAPE_REGEX = /[\n\r"]/;
808
809
  function isXMLRichTextLink(value) {
809
810
  return typeof value === "object" && value != null;
810
811
  }
@@ -951,23 +952,27 @@ function createMDXComponent(variant, properties) {
951
952
  let returnString = "";
952
953
  switch (variant) {
953
954
  case "inlineImage":
954
- returnString = `<InlineImage uuid="${uuid}" ${content != null && content !== "" ? `content="${content}"` : ""} height={${height ?? "null"}} width={${width ?? "null"}} />`;
955
+ returnString = `<InlineImage uuid="${uuid}"${createMDXStringAttribute("content", content)} height={${height ?? "null"}} width={${width ?? "null"}} />`;
955
956
  break;
956
957
  case "internalLink":
957
- returnString = `<InternalLink uuid="${uuid}"${content != null && content !== "" ? ` content="${content}"` : ""}>${text}</InternalLink>`;
958
+ returnString = `<InternalLink uuid="${uuid}"${createMDXStringAttribute("content", content)}>${text}</InternalLink>`;
958
959
  break;
959
960
  case "externalLink":
960
- returnString = `<ExternalLink href="${href == null ? "#" : transformPermanentIdentificationUrl(href)}"${content != null && content !== "" ? ` content="${content}"` : ""}>${text}</ExternalLink>`;
961
+ returnString = `<ExternalLink href="${href == null ? "#" : transformPermanentIdentificationUrl(href)}"${createMDXStringAttribute("content", content)}>${text}</ExternalLink>`;
961
962
  break;
962
963
  case "documentLink":
963
- returnString = String.raw`<ExternalLink href="https:\/\/ochre.lib.uchicago.edu/ochre/v2/ochre.php?uuid=${uuid}&load"${content != null && content !== "" ? ` content="${content}"` : ""}>${text}</ExternalLink>`;
964
+ returnString = String.raw`<ExternalLink href="https:\/\/ochre.lib.uchicago.edu/ochre/v2/ochre.php?uuid=${uuid}&load"${createMDXStringAttribute("content", content)}>${text}</ExternalLink>`;
964
965
  break;
965
966
  case "tooltipSpan":
966
- returnString = `<TooltipSpan${content != null && content !== "" ? ` content="${content}"` : ""}>${text}</TooltipSpan>`;
967
+ returnString = `<TooltipSpan${createMDXStringAttribute("content", content)}>${text}</TooltipSpan>`;
967
968
  break;
968
969
  }
969
970
  return returnString;
970
971
  }
972
+ function createMDXStringAttribute(name, value) {
973
+ if (value == null || value === "") return "";
974
+ return ` ${name}=${MDX_QUOTED_ATTRIBUTE_ESCAPE_REGEX.test(value) ? `{${JSON.stringify(value)}}` : `"${value}"`}`;
975
+ }
971
976
  function applyWhitespaceToResult(result, whitespace, rendering) {
972
977
  return whitespace == null ? result : parseWhitespace(result, whitespace, rendering);
973
978
  }
@@ -1110,7 +1115,7 @@ function createInternalLinkComponent(properties) {
1110
1115
  case "hover-card": return `<Annotation type="hover-card" uuid="${properties.uuid}">${innerContent}</Annotation>`;
1111
1116
  case "item-page": return `<InternalLink type="item" uuid="${properties.uuid}">${innerContent}</InternalLink>`;
1112
1117
  case "entry-page": return `<InternalLink type="entry" uuid="${properties.uuid}">${innerContent}</InternalLink>`;
1113
- default: return `<InternalLink uuid="${properties.uuid}"${properties.propertyMetadata != null ? ` properties="${properties.propertyMetadata.labelUuid}"${properties.propertyMetadata.valueUuid != null ? ` value="${properties.propertyMetadata.valueUuid}"` : ""}` : ""}${properties.content != null && properties.content !== "" ? ` content="${properties.content}"` : ""}>${innerContent}</InternalLink>`;
1118
+ default: return `<InternalLink uuid="${properties.uuid}"${properties.propertyMetadata != null ? ` properties="${properties.propertyMetadata.labelUuid}"${properties.propertyMetadata.valueUuid != null ? ` value="${properties.propertyMetadata.valueUuid}"` : ""}` : ""}${createMDXStringAttribute("content", properties.content)}>${innerContent}</InternalLink>`;
1114
1119
  }
1115
1120
  }
1116
1121
  function getXMLRichTextLinks(item) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ochre-sdk",
3
- "version": "1.0.0-beta.11",
3
+ "version": "1.0.0-beta.12",
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",