@@ -204,7 +204,7 @@ const transformTags: IExtendedSanitizeOptions["transformTags"] = {
204
204
attribs . style += "height: 100%;" ;
205
205
}
206
206
207
- attribs . src = mediaFromMxc ( src ) . getThumbnailOfSourceHttp ( width , height ) ;
207
+ attribs . src = mediaFromMxc ( src ) . getThumbnailOfSourceHttp ( width , height ) ! ;
208
208
return { tagName, attribs } ;
209
209
} ,
210
210
"code" : function ( tagName : string , attribs : sanitizeHtml . Attributes ) {
@@ -352,7 +352,7 @@ const topicSanitizeHtmlParams: IExtendedSanitizeOptions = {
352
352
} ;
353
353
354
354
abstract class BaseHighlighter < T extends React . ReactNode > {
355
- public constructor ( public highlightClass : string , public highlightLink : string ) { }
355
+ public constructor ( public highlightClass : string , public highlightLink ? : string ) { }
356
356
357
357
/**
358
358
* apply the highlights to a section of text
@@ -504,7 +504,7 @@ function formatEmojis(message: string, isHtmlMessage: boolean): (JSX.Element | s
504
504
export function bodyToHtml ( content : IContent , highlights : Optional < string [ ] > , opts : IOptsReturnString ) : string ;
505
505
export function bodyToHtml ( content : IContent , highlights : Optional < string [ ] > , opts : IOptsReturnNode ) : ReactNode ;
506
506
export function bodyToHtml ( content : IContent , highlights : Optional < string [ ] > , opts : IOpts = { } ) : ReactNode | string {
507
- const isFormattedBody = content . format === "org.matrix.custom.html" && ! ! content . formatted_body ;
507
+ const isFormattedBody = content . format === "org.matrix.custom.html" && typeof content . formatted_body === "string" ;
508
508
let bodyHasEmoji = false ;
509
509
let isHtmlMessage = false ;
510
510
@@ -514,7 +514,7 @@ export function bodyToHtml(content: IContent, highlights: Optional<string[]>, op
514
514
}
515
515
516
516
let strippedBody : string ;
517
- let safeBody : string ; // safe, sanitised HTML, preferred over `strippedBody` which is fully plaintext
517
+ let safeBody : string | undefined ; // safe, sanitised HTML, preferred over `strippedBody` which is fully plaintext
518
518
519
519
try {
520
520
// sanitizeHtml can hang if an unclosed HTML tag is thrown at it
@@ -529,7 +529,7 @@ export function bodyToHtml(content: IContent, highlights: Optional<string[]>, op
529
529
530
530
if ( opts . stripReplyFallback && formattedBody ) formattedBody = stripHTMLReply ( formattedBody ) ;
531
531
strippedBody = opts . stripReplyFallback ? stripPlainReply ( plainBody ) : plainBody ;
532
- bodyHasEmoji = mightContainEmoji ( isFormattedBody ? formattedBody : plainBody ) ;
532
+ bodyHasEmoji = mightContainEmoji ( isFormattedBody ? formattedBody ! : plainBody ) ;
533
533
534
534
const highlighter = safeHighlights ?. length
535
535
? new HtmlHighlighter ( "mx_EventTile_searchHighlight" , opts . highlightLink )
@@ -543,11 +543,11 @@ export function bodyToHtml(content: IContent, highlights: Optional<string[]>, op
543
543
// by an attempt to search for 'foobar'. Then again, the search query probably wouldn't work either
544
544
// XXX: hacky bodge to temporarily apply a textFilter to the sanitizeParams structure.
545
545
sanitizeParams . textFilter = function ( safeText ) {
546
- return highlighter . applyHighlights ( safeText , safeHighlights ) . join ( "" ) ;
546
+ return highlighter . applyHighlights ( safeText , safeHighlights ! ) . join ( "" ) ;
547
547
} ;
548
548
}
549
549
550
- safeBody = sanitizeHtml ( formattedBody , sanitizeParams ) ;
550
+ safeBody = sanitizeHtml ( formattedBody ! , sanitizeParams ) ;
551
551
const phtml = cheerio . load ( safeBody , {
552
552
// @ts -ignore: The `_useHtmlParser2` internal option is the
553
553
// simplest way to both parse and render using `htmlparser2`.
@@ -574,7 +574,7 @@ export function bodyToHtml(content: IContent, highlights: Optional<string[]>, op
574
574
safeBody = formatEmojis ( safeBody , true ) . join ( "" ) ;
575
575
}
576
576
} else if ( highlighter ) {
577
- safeBody = highlighter . applyHighlights ( plainBody , safeHighlights ) . join ( "" ) ;
577
+ safeBody = highlighter . applyHighlights ( plainBody , safeHighlights ! ) . join ( "" ) ;
578
578
}
579
579
} finally {
580
580
delete sanitizeParams . textFilter ;
@@ -597,9 +597,7 @@ export function bodyToHtml(content: IContent, highlights: Optional<string[]>, op
597
597
598
598
const match = BIGEMOJI_REGEX . exec ( contentBodyTrimmed ) ;
599
599
emojiBody =
600
- match &&
601
- match [ 0 ] &&
602
- match [ 0 ] . length === contentBodyTrimmed . length &&
600
+ match ?. [ 0 ] ?. length === contentBodyTrimmed . length &&
603
601
// Prevent user pills expanding for users with only emoji in
604
602
// their username. Permalinks (links in pills) can be any URL
605
603
// now, so we just check for an HTTP-looking thing.
@@ -614,7 +612,7 @@ export function bodyToHtml(content: IContent, highlights: Optional<string[]>, op
614
612
"markdown-body" : isHtmlMessage && ! emojiBody ,
615
613
} ) ;
616
614
617
- let emojiBodyElements : JSX . Element [ ] ;
615
+ let emojiBodyElements : JSX . Element [ ] | undefined ;
618
616
if ( ! safeBody && bodyHasEmoji ) {
619
617
emojiBodyElements = formatEmojis ( strippedBody , false ) as JSX . Element [ ] ;
620
618
}
@@ -649,18 +647,18 @@ export function topicToHtml(
649
647
allowExtendedHtml = false ,
650
648
) : ReactNode {
651
649
if ( ! SettingsStore . getValue ( "feature_html_topic" ) ) {
652
- htmlTopic = null ;
650
+ htmlTopic = undefined ;
653
651
}
654
652
655
653
let isFormattedTopic = ! ! htmlTopic ;
656
654
let topicHasEmoji = false ;
657
655
let safeTopic = "" ;
658
656
659
657
try {
660
- topicHasEmoji = mightContainEmoji ( isFormattedTopic ? htmlTopic : topic ) ;
658
+ topicHasEmoji = mightContainEmoji ( isFormattedTopic ? htmlTopic ! : topic ) ;
661
659
662
660
if ( isFormattedTopic ) {
663
- safeTopic = sanitizeHtml ( htmlTopic , allowExtendedHtml ? sanitizeHtmlParams : topicSanitizeHtmlParams ) ;
661
+ safeTopic = sanitizeHtml ( htmlTopic ! , allowExtendedHtml ? sanitizeHtmlParams : topicSanitizeHtmlParams ) ;
664
662
if ( topicHasEmoji ) {
665
663
safeTopic = formatEmojis ( safeTopic , true ) . join ( "" ) ;
666
664
}
@@ -669,7 +667,7 @@ export function topicToHtml(
669
667
isFormattedTopic = false ; // Fall back to plain-text topic
670
668
}
671
669
672
- let emojiBodyElements : ReturnType < typeof formatEmojis > ;
670
+ let emojiBodyElements : ReturnType < typeof formatEmojis > | undefined ;
673
671
if ( ! isFormattedTopic && topicHasEmoji ) {
674
672
emojiBodyElements = formatEmojis ( topic , false ) ;
675
673
}
0 commit comments