ochre-sdk 1.0.16 → 1.0.17
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/mdx.d.mts +2 -1
- package/dist/parsers/mdx.mjs +16 -3
- package/dist/parsers/string.mjs +6 -5
- package/package.json +1 -1
package/dist/parsers/mdx.d.mts
CHANGED
package/dist/parsers/mdx.mjs
CHANGED
|
@@ -1,9 +1,22 @@
|
|
|
1
1
|
//#region src/parsers/mdx.ts
|
|
2
2
|
const MDX_LITERAL_EXPRESSION_REGEX = /[!#*<>[\]_`{|}~]/;
|
|
3
3
|
const MDX_LITERAL_BLOCK_REGEX = /(?:^|\n)[\t ]*(?:import|export|[+>-]|\d+[).])(?:[\t ]|$)/;
|
|
4
|
+
const MDX_MULTIPLE_SPACES_REGEX = / {2,}/g;
|
|
5
|
+
const MDX_INLINE_BOUNDARY_PATTERN = "(?:Annotation|ExternalLink|InlineImage|InternalLink|TooltipSpan|em|strong|u)";
|
|
6
|
+
const MDX_INLINE_BOUNDARY_SPACES_REGEX = new RegExp(String.raw`(\}|<\/${MDX_INLINE_BOUNDARY_PATTERN}>|\/>)([\t ]+)(?=\{|<\/?${MDX_INLINE_BOUNDARY_PATTERN}\b)`, "g");
|
|
7
|
+
const MDX_INLINE_BOUNDARY_REGEX = new RegExp(String.raw`(?:\}[\t ]*|<\/${MDX_INLINE_BOUNDARY_PATTERN}>|\/>)(?=\{|<\/?${MDX_INLINE_BOUNDARY_PATTERN}\b)`);
|
|
8
|
+
function preserveMultipleSpaces(value) {
|
|
9
|
+
return value.replaceAll(MDX_MULTIPLE_SPACES_REGEX, (spaces) => `${spaces.slice(0, 1)}${"\xA0".repeat(spaces.length - 1)}`);
|
|
10
|
+
}
|
|
4
11
|
function serializeMDXText(value) {
|
|
5
|
-
|
|
6
|
-
|
|
12
|
+
const displaySafeValue = preserveMultipleSpaces(value);
|
|
13
|
+
if (displaySafeValue === "" || !(displaySafeValue !== value) && !MDX_LITERAL_EXPRESSION_REGEX.test(displaySafeValue) && !MDX_LITERAL_BLOCK_REGEX.test(displaySafeValue)) return displaySafeValue;
|
|
14
|
+
return `{${JSON.stringify(displaySafeValue)}}`;
|
|
15
|
+
}
|
|
16
|
+
function serializeMDXContent(value) {
|
|
17
|
+
const content = value.replaceAll(MDX_INLINE_BOUNDARY_SPACES_REGEX, (_, previousBoundary, spaces) => `${previousBoundary}{${JSON.stringify(preserveMultipleSpaces(spaces))}}`);
|
|
18
|
+
if (!MDX_INLINE_BOUNDARY_REGEX.test(content)) return content;
|
|
19
|
+
return content.endsWith("\n") ? `<>\n${content}</>` : `<>\n${content}\n</>`;
|
|
7
20
|
}
|
|
8
21
|
//#endregion
|
|
9
|
-
export { serializeMDXText };
|
|
22
|
+
export { serializeMDXContent, serializeMDXText };
|
package/dist/parsers/string.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { TEXT_ANNOTATION_UUID } from "../constants.mjs";
|
|
2
|
-
import { serializeMDXText } from "./mdx.mjs";
|
|
2
|
+
import { serializeMDXContent, serializeMDXText } from "./mdx.mjs";
|
|
3
3
|
import { MultilingualString } from "./multilingual.mjs";
|
|
4
4
|
import { renderOptionsSchema } from "../schemas.mjs";
|
|
5
5
|
import { getXMLSourceIndex } from "../xml/metadata.mjs";
|
|
@@ -419,15 +419,16 @@ function parseXMLContent(item, options) {
|
|
|
419
419
|
return MultilingualString.empty(languages, { aliases });
|
|
420
420
|
}
|
|
421
421
|
function parseXMLContentItem(contentItem, options) {
|
|
422
|
+
const richText = parseNestedStringItems(contentItem.string, contentItem, {
|
|
423
|
+
...options,
|
|
424
|
+
rendering: "rich"
|
|
425
|
+
});
|
|
422
426
|
return {
|
|
423
427
|
text: parseNestedStringItems(contentItem.string, contentItem, {
|
|
424
428
|
...options,
|
|
425
429
|
rendering: "plain"
|
|
426
430
|
}),
|
|
427
|
-
richText:
|
|
428
|
-
...options,
|
|
429
|
-
rendering: "rich"
|
|
430
|
-
})
|
|
431
|
+
richText: serializeMDXContent(richText)
|
|
431
432
|
};
|
|
432
433
|
}
|
|
433
434
|
/**
|