ochre-sdk 1.0.23 → 1.0.25
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/index.mjs +1 -1
- package/dist/parsers/string.mjs +41 -5
- package/package.json +2 -2
package/dist/parsers/index.mjs
CHANGED
|
@@ -1320,7 +1320,7 @@ function parseItem(rawData, options) {
|
|
|
1320
1320
|
abbreviation: rawOchre.belongsTo
|
|
1321
1321
|
};
|
|
1322
1322
|
const metadata = parseMetadata(rawOchre, parserOptions, defaultLanguage);
|
|
1323
|
-
const persistentUrl =
|
|
1323
|
+
const persistentUrl = rawOchre.persistentUrl ?? null;
|
|
1324
1324
|
const item = parseTopLevelItem(rawOchre, category, parserOptions);
|
|
1325
1325
|
if (category === "resource") {
|
|
1326
1326
|
const rawResource = getSingleTopLevelRawItem("resource" in rawOchre ? rawOchre.resource : null, "resource");
|
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/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "ochre-sdk",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.25",
|
|
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",
|
|
@@ -79,7 +79,7 @@
|
|
|
79
79
|
"eslint": "^10.4.0",
|
|
80
80
|
"knip": "^6.14.2",
|
|
81
81
|
"prettier": "^3.8.3",
|
|
82
|
-
"tsdown": "^0.22.
|
|
82
|
+
"tsdown": "^0.22.1",
|
|
83
83
|
"typescript": "^6.0.3",
|
|
84
84
|
"vitest": "^4.1.7"
|
|
85
85
|
},
|