ochre-sdk 1.0.22 → 1.0.24
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/parsers/string.mjs +41 -5
- package/dist/xml/schemas.mjs +2 -2
- package/package.json +1 -1
package/dist/parsers/string.mjs
CHANGED
|
@@ -12,6 +12,9 @@ const ITEM_PAGE_TOKEN = "item-page";
|
|
|
12
12
|
const ENTRY_PAGE_TOKEN = "entry-page";
|
|
13
13
|
const VARIANT_TOKEN = "variant";
|
|
14
14
|
const HEADING_LEVEL_TOKEN = "heading-level";
|
|
15
|
+
const RAW_MDX_BLOCK_DELIMITER = "```***```";
|
|
16
|
+
const RAW_MDX_BLOCK_PLACEHOLDER_PREFIX = "\0raw-mdx-block:";
|
|
17
|
+
const RAW_MDX_BLOCK_PLACEHOLDER_SUFFIX = "\0";
|
|
15
18
|
const MDX_QUOTED_ATTRIBUTE_ESCAPE_REGEX = /[\n\r"]/;
|
|
16
19
|
const MDX_RENDER_ELEMENTS = {
|
|
17
20
|
bold: "strong",
|
|
@@ -252,7 +255,37 @@ function parseXMLStringItem(item, contentItem, options) {
|
|
|
252
255
|
}
|
|
253
256
|
function parseNestedStringItems(items, contentItem, options) {
|
|
254
257
|
let result = "";
|
|
255
|
-
|
|
258
|
+
let rawMDXBlockStartIndex = null;
|
|
259
|
+
for (const [index, item] of items.entries()) {
|
|
260
|
+
if (item.payload === RAW_MDX_BLOCK_DELIMITER && item.rend == null && item.links == null && item.properties == null && item.annotation == null && item.string == null) {
|
|
261
|
+
if (rawMDXBlockStartIndex == null) {
|
|
262
|
+
rawMDXBlockStartIndex = index;
|
|
263
|
+
continue;
|
|
264
|
+
}
|
|
265
|
+
let rawMDXBlock = "";
|
|
266
|
+
for (let rawIndex = rawMDXBlockStartIndex + 1; rawIndex < index; rawIndex += 1) {
|
|
267
|
+
const rawItem = items[rawIndex];
|
|
268
|
+
if (rawItem != null) rawMDXBlock += parseXMLStringItem(rawItem, contentItem, {
|
|
269
|
+
languages: options.languages,
|
|
270
|
+
rendering: "plain"
|
|
271
|
+
});
|
|
272
|
+
}
|
|
273
|
+
if (item.whitespace?.split(" ").includes("newline") === true) rawMDXBlock += "\n";
|
|
274
|
+
if (options.rendering === "rich" && options.rawMDXBlocks != null) {
|
|
275
|
+
const placeholder = `${RAW_MDX_BLOCK_PLACEHOLDER_PREFIX}${options.rawMDXBlocks.length}${RAW_MDX_BLOCK_PLACEHOLDER_SUFFIX}`;
|
|
276
|
+
options.rawMDXBlocks.push(rawMDXBlock);
|
|
277
|
+
result += placeholder;
|
|
278
|
+
} else result += rawMDXBlock;
|
|
279
|
+
rawMDXBlockStartIndex = null;
|
|
280
|
+
continue;
|
|
281
|
+
}
|
|
282
|
+
if (rawMDXBlockStartIndex != null) continue;
|
|
283
|
+
result += parseXMLStringItem(item, contentItem, options);
|
|
284
|
+
}
|
|
285
|
+
if (rawMDXBlockStartIndex != null) for (let index = rawMDXBlockStartIndex; index < items.length; index += 1) {
|
|
286
|
+
const item = items[index];
|
|
287
|
+
if (item != null) result += parseXMLStringItem(item, contentItem, options);
|
|
288
|
+
}
|
|
256
289
|
return result;
|
|
257
290
|
}
|
|
258
291
|
function isTextAnnotationMarkerLink(link) {
|
|
@@ -419,16 +452,19 @@ function parseXMLContent(item, options) {
|
|
|
419
452
|
return MultilingualString.empty(languages, { aliases });
|
|
420
453
|
}
|
|
421
454
|
function parseXMLContentItem(contentItem, options) {
|
|
422
|
-
const
|
|
455
|
+
const rawMDXBlocks = [];
|
|
456
|
+
let serializedRichText = serializeMDXContent(parseNestedStringItems(contentItem.string, contentItem, {
|
|
423
457
|
...options,
|
|
424
|
-
rendering: "rich"
|
|
425
|
-
|
|
458
|
+
rendering: "rich",
|
|
459
|
+
rawMDXBlocks
|
|
460
|
+
}));
|
|
461
|
+
for (const [index, rawMDXBlock] of rawMDXBlocks.entries()) serializedRichText = serializedRichText.replaceAll(`${RAW_MDX_BLOCK_PLACEHOLDER_PREFIX}${index}${RAW_MDX_BLOCK_PLACEHOLDER_SUFFIX}`, rawMDXBlock);
|
|
426
462
|
return {
|
|
427
463
|
text: parseNestedStringItems(contentItem.string, contentItem, {
|
|
428
464
|
...options,
|
|
429
465
|
rendering: "plain"
|
|
430
466
|
}),
|
|
431
|
-
richText:
|
|
467
|
+
richText: serializedRichText
|
|
432
468
|
};
|
|
433
469
|
}
|
|
434
470
|
/**
|
package/dist/xml/schemas.mjs
CHANGED
|
@@ -201,7 +201,7 @@ const XMLImage = v.object({
|
|
|
201
201
|
fileSize: XMLOptionalNumber,
|
|
202
202
|
payload: v.optional(v.string("XMLImage: payload is string and optional"))
|
|
203
203
|
}, "XMLImage: Shape error");
|
|
204
|
-
const XMLImageMapArea = v.
|
|
204
|
+
const XMLImageMapArea = v.object({
|
|
205
205
|
uuid: v.pipe(v.string("XMLImageMapArea: uuid is string and required"), v.check(isPseudoUuid, "XMLImageMapArea: uuid is not a valid pseudo-UUID")),
|
|
206
206
|
publicationDateTime: v.optional(customDateTime("XMLImageMapArea: publicationDateTime is not a valid datetime")),
|
|
207
207
|
type: v.string("XMLImageMapArea: type is string and required"),
|
|
@@ -213,7 +213,7 @@ const XMLImageMapArea = v.pipe(v.object({
|
|
|
213
213
|
"poly"
|
|
214
214
|
], "XMLImageMapArea: shape is rect, circle, or poly"),
|
|
215
215
|
coords: v.string("XMLImageMapArea: coords is string and required")
|
|
216
|
-
}, "XMLImageMapArea: Shape error")
|
|
216
|
+
}, "XMLImageMapArea: Shape error");
|
|
217
217
|
const XMLImageMap = v.object({
|
|
218
218
|
area: v.array(XMLImageMapArea, "XMLImageMap: area is array of XMLImageMapArea"),
|
|
219
219
|
width: XMLNumber,
|