@@ -52,12 +52,12 @@ function isListChild(n: Node): boolean {
5252 return LIST_TYPES . includes ( n . parentNode ?. nodeName ) ;
5353}
5454
55- function parseAtRoomMentions ( text : string , pc : PartCreator ) : Part [ ] {
55+ function parseAtRoomMentions ( text : string , pc : PartCreator , shouldEscape = true ) : Part [ ] {
5656 const ATROOM = "@room" ;
5757 const parts : Part [ ] = [ ] ;
5858 text . split ( ATROOM ) . forEach ( ( textPart , i , arr ) => {
5959 if ( textPart . length ) {
60- parts . push ( ...pc . plainWithEmoji ( escape ( textPart ) ) ) ;
60+ parts . push ( ...pc . plainWithEmoji ( shouldEscape ? escape ( textPart ) : textPart ) ) ;
6161 }
6262 // it's safe to never append @room after the last textPart
6363 // as split will report an empty string at the end if
@@ -261,13 +261,17 @@ function parseHtmlMessage(html: string, pc: PartCreator, isQuotedMessage: boolea
261261 return parts ;
262262}
263263
264- export function parsePlainTextMessage ( body : string , pc : PartCreator , isQuotedMessage ?: boolean ) : Part [ ] {
264+ export function parsePlainTextMessage (
265+ body : string ,
266+ pc : PartCreator ,
267+ opts : { isQuotedMessage ?: boolean , shouldEscape ?: boolean } ,
268+ ) : Part [ ] {
265269 const lines = body . split ( / \r \n | \r | \n / g) ; // split on any new-line combination not just \n, collapses \r\n
266270 return lines . reduce ( ( parts , line , i ) => {
267- if ( isQuotedMessage ) {
271+ if ( opts . isQuotedMessage ) {
268272 parts . push ( pc . plain ( "> " ) ) ;
269273 }
270- parts . push ( ...parseAtRoomMentions ( line , pc ) ) ;
274+ parts . push ( ...parseAtRoomMentions ( line , pc , opts . shouldEscape ) ) ;
271275 const isLast = i === lines . length - 1 ;
272276 if ( ! isLast ) {
273277 parts . push ( pc . newline ( ) ) ;
@@ -288,7 +292,7 @@ export function parseEvent(event: MatrixEvent, pc: PartCreator, { isQuotedMessag
288292 isRainbow = true ;
289293 }
290294 } else {
291- parts = parsePlainTextMessage ( content . body || "" , pc , isQuotedMessage ) ;
295+ parts = parsePlainTextMessage ( content . body || "" , pc , { isQuotedMessage } ) ;
292296 }
293297
294298 if ( isEmote && isRainbow ) {
0 commit comments