ochre-sdk 1.0.23 → 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/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
|
/**
|