@@ -35,34 +35,42 @@ it("keeps keyboard scrolling available as a streamed equation outgrows its viewp
3535 await expect . element ( screen . getByRole ( "button" , { name : "After equation" } ) ) . toHaveFocus ( ) ;
3636} ) ;
3737
38- it ( "typesets a display equation whose label has an unescaped percent" , async ( ) => {
39- const tex =
40- "R_e=\\underbrace{\\frac{1.0176}{32}}_{\\text{3.18% dividend yield}}+\\underbrace{6\\%}_{\\text{growth}}=\\boxed{9.18\\%}" ;
41- const adjacent = "\\text{100%% yield}" ;
42- const paired = "\\begin{aligned}x\\\\%\\end{aligned}" ;
43- const commented = "\\begin{aligned}\nx &= 1 % +999\n\\\\ y &= \\text{2%}\n\\end{aligned}" ;
44- const verbatim = "\\verb|100%|+\\text{2%}" ;
45- await using screen = await render (
46- < >
47- < MarkdownMath tex = { tex } display />
48- < MarkdownMath tex = { adjacent } display />
49- < MarkdownMath tex = { paired } display />
50- < MarkdownMath tex = { commented } display />
51- < MarkdownMath tex = { verbatim } display />
52- </ > ,
53- ) ;
54- await vi . waitFor ( ( ) => expect ( screen . container . querySelector ( ".katex" ) ) . not . toBeNull ( ) ) ;
55- const text = screen . container . textContent ?? "" ;
56- expect ( text ) . toContain ( "9.18%" ) ;
57- expect ( text . replaceAll ( "\u00a0" , " " ) ) . toContain ( "3.18% dividend yield" ) ;
58- const equations = screen . container . querySelectorAll ( "[data-markdown-math]" ) ;
59- expect ( equations [ 0 ] ?. querySelector ( ".katex" ) ) . not . toBeNull ( ) ;
60- expect ( equations [ 1 ] ?. querySelector ( ".katex" ) ) . not . toBeNull ( ) ;
61- expect ( equations [ 1 ] ?. textContent ?. replaceAll ( "\u00a0" , " " ) ) . toContain ( "100%% yield" ) ;
62- expect ( equations [ 2 ] ?. querySelector ( ".katex" ) ) . not . toBeNull ( ) ;
63- expect ( equations [ 3 ] ?. querySelector ( ".katex" ) ) . toBeNull ( ) ;
64- expect ( equations [ 3 ] ?. textContent ) . toBe ( `\\[\n${ commented } \n\\]` ) ;
65- expect ( equations [ 4 ] ?. querySelector ( ".katex" ) ) . toBeNull ( ) ;
66- expect ( equations [ 4 ] ?. textContent ) . toBe ( `\\[\n${ verbatim } \n\\]` ) ;
67- expect ( equations [ 0 ] ?. getAttribute ( "data-markdown-copy" ) ) . toBe ( `\\[\n${ tex } \n\\]\n\n` ) ;
38+ it ( "typesets equations whose labels have an unescaped percent" , async ( ) => {
39+ // The reported multiline equation, line breaks included.
40+ const issue =
41+ "R_e=\\underbrace{\\frac{1.0176}{32}}_{\\text{3.18% dividend yield}}\n+\\underbrace{6\\%}_{\\text{growth}}\n=\\boxed{9.18\\%}" ;
42+ const typeset = [
43+ issue ,
44+ "\\text{100%% yield}" ,
45+ "\\begin{aligned}x\\\\%\\end{aligned}" ,
46+ "\\begin{aligned}\nx &= 1 % +999\n\\\\ y &= \\text{2%}\n\\end{aligned}" ,
47+ "\\verb|50%|+\n\\text{2%}" ,
48+ "x % note\n+ 1" ,
49+ ] ;
50+ const raw = [ "\\frac{1" , "\\text{50 % off}" , "\\verb|50%+\\text{2%}" ] ;
51+ const equations = ( tex : string [ ] ) => tex . map ( ( t ) => < MarkdownMath key = { t } tex = { t } display /> ) ;
52+ await using screen = await render ( < > { equations ( typeset ) } </ > ) ;
53+ const rendered = ( ) => [ ...screen . container . querySelectorAll ( "[data-markdown-math]" ) ] ;
54+ const visibleText = ( index : number ) =>
55+ rendered ( ) [ index ] ?. querySelector ( ".katex-html" ) ?. textContent ?. replaceAll ( "\u00a0" , " " ) ;
56+ await vi . waitFor ( ( ) => {
57+ for ( const equation of rendered ( ) ) expect ( equation . querySelector ( ".katex" ) ) . not . toBeNull ( ) ;
58+ } ) ;
59+ expect ( visibleText ( 0 ) ) . toContain ( "3.18% dividend yield" ) ;
60+ expect ( visibleText ( 0 ) ) . toContain ( "9.18%" ) ;
61+ expect ( rendered ( ) [ 0 ] ?. getAttribute ( "data-markdown-copy" ) ) . toBe ( `\\[\n${ issue } \n\\]\n\n` ) ;
62+ expect ( visibleText ( 1 ) ) . toContain ( "100%% yield" ) ;
63+ expect ( visibleText ( 3 ) ) . toContain ( "2%" ) ;
64+ expect ( visibleText ( 3 ) ) . not . toContain ( "999" ) ;
65+ expect ( visibleText ( 4 ) ) . toContain ( "50%" ) ;
66+ expect ( visibleText ( 4 ) ) . toContain ( "2%" ) ;
67+ expect ( visibleText ( 5 ) ) . not . toContain ( "note" ) ;
68+
69+ // KaTeX has loaded, so these render their final result in this commit.
70+ await screen . rerender ( < > { equations ( [ ...typeset , ...raw ] ) } </ > ) ;
71+ raw . forEach ( ( tex , offset ) => {
72+ const equation = rendered ( ) [ typeset . length + offset ] ;
73+ expect ( equation ?. querySelector ( ".katex" ) ) . toBeNull ( ) ;
74+ expect ( equation ?. textContent ) . toBe ( `\\[\n${ tex } \n\\]` ) ;
75+ } ) ;
6876} ) ;
0 commit comments