@@ -249,6 +249,8 @@ const styles = StyleSheet.create({
249249 minWidth : 0 ,
250250 padding : 5 ,
251251 } ,
252+ tableCellCenter : { textAlign : 'center' } ,
253+ tableCellRight : { textAlign : 'right' } ,
252254 tableHeader : { backgroundColor : '#f1f3f5' , fontWeight : 700 } ,
253255 imageBlock : { marginBottom : 11 } ,
254256 image : { maxHeight : 430 , objectFit : 'contain' , width : '100%' } ,
@@ -451,10 +453,24 @@ function renderImage(
451453 key : string
452454) : ReactNode {
453455 const src = stringAttr ( node , 'src' ) ?? ''
456+ const rawHref = stringAttr ( node , 'href' )
457+ const href = rawHref ? safeLink ( rawHref ) : undefined
454458 const ref = extractEmbeddedFileRef ( src )
455459 const image = ref ? images . get ( markdownPdfImageKey ( ref ) ) : undefined
456460 if ( ! image ) {
457461 const alt = stringAttr ( node , 'alt' )
462+ const fallback = (
463+ < Text style = { styles . imageFallback } >
464+ { renderText ( alt ? `Image: ${ alt } ` : 'Image unavailable' , key ) }
465+ </ Text >
466+ )
467+ if ( href ) {
468+ return (
469+ < Link key = { key } src = { href } >
470+ { fallback }
471+ </ Link >
472+ )
473+ }
458474 return (
459475 < Text key = { key } style = { styles . imageFallback } >
460476 { renderText ( alt ? `Image: ${ alt } ` : 'Image unavailable' , key ) }
@@ -466,6 +482,18 @@ function renderImage(
466482 const width = Number . isFinite ( requestedWidth )
467483 ? Math . min ( Math . max ( requestedWidth , 1 ) , PDF_TABLE_CONTENT_WIDTH )
468484 : undefined
485+ const renderedImage = (
486+ < View style = { styles . imageBlock } >
487+ < Image src = { image } style = { [ styles . image , ...( width ? [ { width } ] : [ ] ) ] } />
488+ </ View >
489+ )
490+ if ( href ) {
491+ return (
492+ < Link key = { key } src = { href } >
493+ { renderedImage }
494+ </ Link >
495+ )
496+ }
469497 return (
470498 < View key = { key } style = { styles . imageBlock } >
471499 < Image src = { image } style = { [ styles . image , ...( width ? [ { width } ] : [ ] ) ] } />
@@ -515,19 +543,31 @@ function renderList(
515543function renderTableRow ( row : JSONContent , key : string , header : boolean ) : ReactNode {
516544 return (
517545 < View key = { key } minPresenceAhead = { header ? 16 : undefined } style = { styles . tableRow } >
518- { ( row . content ?? [ ] ) . map ( ( cell , index ) => (
519- < Text
520- key = { `${ key } -${ index } ` }
521- style = { [ styles . tableCell , ...( header ? [ styles . tableHeader ] : [ ] ) ] }
522- >
523- { ( cell . content ?? [ ] ) . map ( ( child , childIndex ) => (
524- < Text key = { `${ key } -${ index } -${ childIndex } ` } >
525- { childIndex > 0 ? '\n' : null }
526- { renderInline ( `${ key } -${ index } -${ childIndex } ` , child . content ) }
527- </ Text >
528- ) ) }
529- </ Text >
530- ) ) }
546+ { ( row . content ?? [ ] ) . map ( ( cell , index ) => {
547+ const alignmentStyle =
548+ cell . attrs ?. align === 'center'
549+ ? styles . tableCellCenter
550+ : cell . attrs ?. align === 'right'
551+ ? styles . tableCellRight
552+ : undefined
553+ return (
554+ < Text
555+ key = { `${ key } -${ index } ` }
556+ style = { [
557+ styles . tableCell ,
558+ ...( header ? [ styles . tableHeader ] : [ ] ) ,
559+ ...( alignmentStyle ? [ alignmentStyle ] : [ ] ) ,
560+ ] }
561+ >
562+ { ( cell . content ?? [ ] ) . map ( ( child , childIndex ) => (
563+ < Text key = { `${ key } -${ index } -${ childIndex } ` } >
564+ { childIndex > 0 ? '\n' : null }
565+ { renderInline ( `${ key } -${ index } -${ childIndex } ` , child . content ) }
566+ </ Text >
567+ ) ) }
568+ </ Text >
569+ )
570+ } ) }
531571 </ View >
532572 )
533573}
0 commit comments