@adatechnology/content-contracts 0.2.0 → 0.3.0

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.
package/dist/index.cjs CHANGED
@@ -900,6 +900,47 @@ function parseDestination(text, start) {
900
900
  }
901
901
  __name(parseDestination, "parseDestination");
902
902
 
903
+ // src/markdown/paragraphToBlock.ts
904
+ function isFiller(node) {
905
+ return node.type === "break" || node.type === "text" && !node.value.trim();
906
+ }
907
+ __name(isFiller, "isFiller");
908
+ function paragraphToBlock(children) {
909
+ const meaningful = children.filter((node) => !isFiller(node));
910
+ const images = meaningful.filter((node) => node.type === "image");
911
+ if (images.length === 0 || images.length !== meaningful.length) return {
912
+ type: "paragraph",
913
+ children
914
+ };
915
+ const [only] = images;
916
+ if (images.length === 1 && only?.title) {
917
+ return {
918
+ type: "figure",
919
+ image: {
920
+ src: only.src,
921
+ alt: only.alt
922
+ },
923
+ caption: only.title
924
+ };
925
+ }
926
+ if (images.length < 2) return {
927
+ type: "paragraph",
928
+ children
929
+ };
930
+ const gallery = images.map((image) => ({
931
+ src: image.src,
932
+ alt: image.alt,
933
+ ...image.title ? {
934
+ caption: image.title
935
+ } : {}
936
+ }));
937
+ return {
938
+ type: "gallery",
939
+ images: gallery
940
+ };
941
+ }
942
+ __name(paragraphToBlock, "paragraphToBlock");
943
+
903
944
  // src/markdown/parseMarkdown.ts
904
945
  var MAX_BLOCK_DEPTH = 6;
905
946
  var FENCE_PATTERN = /^ {0,3}(`{3,}|~{3,})\s*([^\s`]*)[^`]*$/;
@@ -1021,10 +1062,7 @@ function parseParagraph(lines, index, depth) {
1021
1062
  cursor += 1;
1022
1063
  }
1023
1064
  return {
1024
- block: {
1025
- type: "paragraph",
1026
- children: parseInline(content.join("\n").trimEnd())
1027
- },
1065
+ block: paragraphToBlock(parseInline(content.join("\n").trimEnd())),
1028
1066
  next: cursor
1029
1067
  };
1030
1068
  }
@@ -1136,7 +1174,10 @@ function blockToPlainText(block) {
1136
1174
  return block.children.map(blockToPlainText).join("\n\n");
1137
1175
  case "list":
1138
1176
  return block.items.map((item) => item.map(blockToPlainText).join("\n")).join("\n");
1177
+ case "figure":
1178
+ return block.caption;
1139
1179
  case "thematicBreak":
1180
+ case "gallery":
1140
1181
  return "";
1141
1182
  }
1142
1183
  }
@@ -1232,6 +1273,12 @@ function renderInlineNode(node, context) {
1232
1273
  }
1233
1274
  }
1234
1275
  __name(renderInlineNode, "renderInlineNode");
1276
+ function renderFigure(image, caption) {
1277
+ const img = `<img src="${escapeHtml(image.src)}" alt="${escapeHtml(image.alt)}" loading="lazy" decoding="async">`;
1278
+ const figcaption = caption ? `<figcaption>${escapeHtml(caption)}</figcaption>` : "";
1279
+ return `<figure class="adc-figure">${img}${figcaption}</figure>`;
1280
+ }
1281
+ __name(renderFigure, "renderFigure");
1235
1282
  function renderBlock(block, context, tight = false) {
1236
1283
  switch (block.type) {
1237
1284
  case "heading": {
@@ -1249,6 +1296,10 @@ function renderBlock(block, context, tight = false) {
1249
1296
  }
1250
1297
  case "thematicBreak":
1251
1298
  return "<hr>";
1299
+ case "figure":
1300
+ return renderFigure(block.image, block.caption);
1301
+ case "gallery":
1302
+ return `<div class="adc-gallery" data-count="${block.images.length}">${block.images.map((image) => renderFigure(image, image.caption)).join("")}</div>`;
1252
1303
  case "list": {
1253
1304
  const tag = block.ordered ? "ol" : "ul";
1254
1305
  const start = block.ordered && block.start !== void 0 && block.start !== 1 ? ` start="${block.start}"` : "";