@@ -10,6 +10,13 @@ import ULRenderer from './HTMLEngineProvider/HTMLRenderers/ULRenderer';
1010
1111type LinkPressHandler = NonNullable < RenderersProps [ 'a' ] > [ 'onPress' ] ;
1212
13+ // Matches &#91; (→ "[") and &#93; (→ "]"). Index 7 is the distinguishing digit ('1' vs '3').
14+ const RE_BRACKET_ESCAPE = / & a m p ; # 9 [ 1 3 ] ; / g;
15+ // Matches consecutive duplicate <emoji> or </emoji> tags, keeping only the outermost one.
16+ const RE_EMOJI_OPEN_OR_CLOSE = / ( < e m o j i [ ^ > ] * > ) (?: < e m o j i [ ^ > ] * > ) + | ( < \/ e m o j i [ ^ > ] * > ) (?: < \/ e m o j i [ ^ > ] * > ) + / g;
17+ // Strips orphaned <br/> tags inside <ul> that would render as extra empty bullets.
18+ const RE_BR_CLEANUP = / < b r \s * \/ ? > \s * ( < \/ u l > ) | ( < \/ l i > ) \s * < b r \s * \/ ? > \s * (? = < (?: l i | \/ u l ) > ) / gi;
19+
1320type RenderHTMLProps = {
1421 /** HTML string to render */
1522 html : string ;
@@ -36,14 +43,11 @@ function RenderHTML({html: htmlParam, onLinkPress, isSelectable}: RenderHTMLProp
3643 return (
3744 Parser . replace ( htmlParam , { shouldEscapeText : false , filterRules : [ 'emoji' ] } )
3845 // Escape brackets when pasting a link, since unescaped [] can break Markdown link syntax
39- . replaceAll ( '&#91;' , '[' )
40- . replaceAll ( '&#93;' , ']' )
46+ . replaceAll ( RE_BRACKET_ESCAPE , ( m ) => ( m . at ( 7 ) === '1' ? '[' : ']' ) )
4147 // Remove double <emoji> tag if exists and keep the outermost tag (always the original tag).
42- . replaceAll ( / ( < e m o j i [ ^ > ] * > ) (?: < e m o j i [ ^ > ] * > ) + / g, '$1' )
43- . replaceAll ( / ( < \/ e m o j i [ ^ > ] * > ) (?: < \/ e m o j i [ ^ > ] * > ) + / g, '$1' )
48+ . replaceAll ( RE_EMOJI_OPEN_OR_CLOSE , '$1$2' )
4449 // Strip orphaned <br/> tags inside <ul> that would render as extra empty bullets
45- . replaceAll ( / < b r \s * \/ ? > \s * ( < \/ u l > ) / gi, '$1' )
46- . replaceAll ( / ( < \/ l i > ) \s * < b r \s * \/ ? > \s * (? = < (?: l i | \/ u l ) > ) / gi, '$1' )
50+ . replaceAll ( RE_BR_CLEANUP , '$1$2' )
4751 ) ;
4852 } , [ htmlParam ] ) ;
4953
0 commit comments