@@ -16,6 +16,7 @@ import {
1616 TEXT_ANNOTATION_TEXT_STYLING_VARIANT_UUID ,
1717 TEXT_ANNOTATION_UUID ,
1818} from "#/constants.js" ;
19+ import { serializeMDXText } from "#/parsers/mdx.js" ;
1920import { MultilingualString } from "#/parsers/multilingual.js" ;
2021import { renderOptionsSchema , whitespaceSchema } from "#/schemas.js" ;
2122import { getXMLSourceIndex } from "#/xml/metadata.js" ;
@@ -254,10 +255,8 @@ function parseXMLStringPayload(
254255 string : XMLString ,
255256 options : { rendering : TextRendering } ,
256257) : string {
257- return ( string . payload ?? "" )
258- . replaceAll ( "<" , options . rendering === "rich" ? String . raw `\<` : "<" )
259- . replaceAll ( "{" , String . raw `\{` )
260- . replaceAll ( "}" , String . raw `\}` ) ;
258+ const payload = string . payload ?? "" ;
259+ return options . rendering === "rich" ? serializeMDXText ( payload ) : payload ;
261260}
262261
263262export function parseXMLString ( string : XMLString ) : MultilingualStringText {
@@ -304,28 +303,40 @@ function createMDXComponent(
304303
305304 switch ( variant ) {
306305 case "inlineImage" : {
307- returnString = `<InlineImage uuid="${ uuid } "${ createMDXStringAttribute (
306+ returnString = `<InlineImage${ createMDXStringAttribute (
307+ "uuid" ,
308+ uuid ?? "null" ,
309+ ) } ${ createMDXStringAttribute (
308310 "content" ,
309311 content ,
310312 ) } height={${ height ?? "null" } } width={${ width ?? "null" } } />`;
311313 break ;
312314 }
313315 case "internalLink" : {
314- returnString = `<InternalLink uuid="${ uuid } "${ createMDXStringAttribute (
316+ returnString = `<InternalLink${ createMDXStringAttribute (
317+ "uuid" ,
318+ uuid ?? "null" ,
319+ ) } ${ createMDXStringAttribute (
315320 "content" ,
316321 tooltipContent ,
317322 ) } >${ text } </InternalLink>`;
318323 break ;
319324 }
320325 case "externalLink" : {
321- returnString = `<ExternalLink href="${ href == null ? "#" : transformPermanentIdentificationUrl ( href ) } "${ createMDXStringAttribute (
326+ returnString = `<ExternalLink${ createMDXStringAttribute (
327+ "href" ,
328+ href == null ? "#" : transformPermanentIdentificationUrl ( href ) ,
329+ ) } ${ createMDXStringAttribute (
322330 "content" ,
323331 tooltipContent ,
324332 ) } >${ text } </ExternalLink>`;
325333 break ;
326334 }
327335 case "documentLink" : {
328- returnString = String . raw `<ExternalLink href="https:\/\/ochre.lib.uchicago.edu/ochre/v2/ochre.php?uuid=${ uuid } &load"${ createMDXStringAttribute (
336+ returnString = `<ExternalLink${ createMDXStringAttribute (
337+ "href" ,
338+ `https://ochre.lib.uchicago.edu/ochre/v2/ochre.php?uuid=${ uuid } &load` ,
339+ ) } ${ createMDXStringAttribute (
329340 "content" ,
330341 tooltipContent ,
331342 ) } >${ text } </ExternalLink>`;
@@ -693,11 +704,13 @@ function wrapWithTextStyling(
693704 return content ;
694705 }
695706
696- return `<Annotation type="text-styling" variant="${ textStyling . variant } " size="${ textStyling . size } "${
697- textStyling . headingLevel != null
698- ? ` headingLevel="${ textStyling . headingLevel } "`
699- : ""
700- } ${
707+ return `<Annotation type="text-styling"${ createMDXStringAttribute (
708+ "variant" ,
709+ textStyling . variant ,
710+ ) } ${ createMDXStringAttribute ( "size" , textStyling . size ) } ${ createMDXStringAttribute (
711+ "headingLevel" ,
712+ textStyling . headingLevel ?? undefined ,
713+ ) } ${
701714 textStyling . cssStyles . length > 0
702715 ? ` cssStyles={{default: ${ JSON . stringify ( textStyling . cssStyles ) } , tablet: [], mobile: []}}`
703716 : ""
@@ -718,22 +731,36 @@ function createInternalLinkComponent(properties: {
718731
719732 switch ( properties . annotationMetadata . linkVariant ) {
720733 case "hover-card" : {
721- return `<Annotation type="hover-card" uuid="${ properties . uuid } ">${ innerContent } </Annotation>` ;
734+ return `<Annotation type="hover-card"${ createMDXStringAttribute (
735+ "uuid" ,
736+ properties . uuid ?? "null" ,
737+ ) } >${ innerContent } </Annotation>`;
722738 }
723739 case "item-page" : {
724- return `<InternalLink type="item" uuid="${ properties . uuid } ">${ innerContent } </InternalLink>` ;
740+ return `<InternalLink type="item"${ createMDXStringAttribute (
741+ "uuid" ,
742+ properties . uuid ?? "null" ,
743+ ) } >${ innerContent } </InternalLink>`;
725744 }
726745 case "entry-page" : {
727- return `<InternalLink type="entry" uuid="${ properties . uuid } ">${ innerContent } </InternalLink>` ;
746+ return `<InternalLink type="entry"${ createMDXStringAttribute (
747+ "uuid" ,
748+ properties . uuid ?? "null" ,
749+ ) } >${ innerContent } </InternalLink>`;
728750 }
729751 default : {
730- return `<InternalLink uuid="${ properties . uuid } "${
752+ return `<InternalLink${ createMDXStringAttribute (
753+ "uuid" ,
754+ properties . uuid ?? "null" ,
755+ ) } ${
731756 properties . propertyMetadata != null
732- ? ` properties="${ properties . propertyMetadata . labelUuid } "${
733- properties . propertyMetadata . valueUuid != null
734- ? ` value="${ properties . propertyMetadata . valueUuid } "`
735- : ""
736- } `
757+ ? `${ createMDXStringAttribute (
758+ "properties" ,
759+ properties . propertyMetadata . labelUuid ,
760+ ) } ${ createMDXStringAttribute (
761+ "value" ,
762+ properties . propertyMetadata . valueUuid ?? undefined ,
763+ ) } `
737764 : ""
738765 } ${ createMDXStringAttribute (
739766 "content" ,
0 commit comments