@@ -171,4 +171,34 @@ describe("RA preview", () => {
171171 const opMatches = html . match ( / r a - p r e v - o p / g) ;
172172 expect ( opMatches ! . length ) . toBeGreaterThanOrEqual ( 2 ) ;
173173 } ) ;
174+
175+ it ( "should not treat underscore-prefixed column names as LaTeX subscript" , ( ) => {
176+ const html = renderRAPreview ( "PI _name, person_id Person" ) ;
177+ // _name should not be split — the underscore is part of the column name
178+ expect ( html ) . toMatch ( / < s u b [ ^ > ] * > .* _ n a m e .* p e r s o n _ i d .* < \/ s u b > / ) ;
179+ expect ( html ) . not . toMatch ( / o p a c i t y / ) ; // no faint bracket styling for _
180+ } ) ;
181+ } ) ;
182+
183+ describe ( "RA highlighter character preservation with underscore columns" , ( ) => {
184+ it ( "should preserve character count with underscore-prefixed columns" , ( ) => {
185+ const input = "PI _name, person_id (Person)" ;
186+ const html = highlightRA ( input ) ;
187+ const textOnly = html
188+ . replace ( / < [ ^ > ] + > / g, "" )
189+ . replace ( / & l t ; / g, "<" ) . replace ( / & g t ; / g, ">" )
190+ . replace ( / & a m p ; / g, "&" ) . replace ( / & q u o t ; / g, '"' ) ;
191+ expect ( textOnly ) . toBe ( input ) ;
192+ } ) ;
193+
194+ it ( "should still handle real _{} LaTeX notation with Unicode symbol" , ( ) => {
195+ const input = "σ_{age > 20}(Person)" ;
196+ const html = highlightRA ( input ) ;
197+ const textOnly = html
198+ . replace ( / < [ ^ > ] + > / g, "" )
199+ . replace ( / & l t ; / g, "<" ) . replace ( / & g t ; / g, ">" )
200+ . replace ( / & a m p ; / g, "&" ) . replace ( / & q u o t ; / g, '"' ) ;
201+ expect ( textOnly ) . toBe ( input ) ;
202+ expect ( html ) . toContain ( "opacity: 0.5" ) ; // _ rendered as faint bracket
203+ } ) ;
174204} ) ;
0 commit comments