@@ -449,14 +449,14 @@ describe('Markdown with tables', () => {
449449 } )
450450
451451 it ( 'keeps surrounding paragraphs intact' , ( ) => {
452- const text = 'Above\n\n| H1 | H2 |\n| ----|----|\n| a | b |\n\nBelow '
453- const { getByText, getByRole } = render ( < Markdown text = { text } /> )
454- expect ( getByText ( 'Above ' ) . tagName ) . toBe ( 'P' )
455- expect ( getByText ( 'Below ' ) . tagName ) . toBe ( 'P' )
456- expect ( getByRole ( 'table' ) ) . toBeDefined ( )
452+ const text = 'alpha | beta\n ---\ngamma '
453+ const { getByText, queryByRole } = render ( < Markdown text = { text } /> )
454+ expect ( getByText ( 'alpha | beta ' ) . tagName ) . toBe ( 'P' )
455+ expect ( getByText ( 'gamma ' ) . tagName ) . toBe ( 'P' )
456+ expect ( queryByRole ( 'table' ) ) . toBeNull ( )
457457 } )
458458
459- it ( 'ignores pipe‑ separated text that lacks a separator line' , ( ) => {
459+ it ( 'ignores pipe- separated text that lacks a separator line' , ( ) => {
460460 const bogus = 'not | a | table'
461461 const { queryByRole, getByText } = render ( < Markdown text = { bogus } /> )
462462 expect ( queryByRole ( 'table' ) ) . toBeNull ( ) // no table
@@ -478,4 +478,30 @@ describe('Markdown with tables', () => {
478478 expect ( getByText ( 'Header1' ) ) . toBeDefined ( )
479479 expect ( getByText ( 'Data2' ) ) . toBeDefined ( )
480480 } )
481+
482+ it ( 'keeps a pipe that is inside inline code in a table' , ( ) => {
483+ const text = 'Header1 | Header2\n------- | -------\n| Here is some `inline | code` with a pipe. |'
484+ const { getByText, getByRole } = render ( < Markdown text = { text } /> )
485+ expect ( getByRole ( 'table' ) ) . toBeDefined ( )
486+ expect ( getByText ( 'inline | code' ) ) . toBeDefined ( )
487+ } )
488+
489+ it ( 'does not treat --- as a table separator' , ( ) => {
490+ const text = 'Column 1 | Column 2\n---\nData 1 | Data 2'
491+ const { queryByRole, getByRole, getByText } = render ( < Markdown text = { text } /> )
492+ expect ( queryByRole ( 'table' ) ) . toBeNull ( ) // no table
493+ expect ( getByText ( 'Column 1 | Column 2' ) ) . toBeDefined ( )
494+ expect ( getByRole ( 'separator' ) ) . toBeDefined ( ) // horizontal rule
495+ expect ( getByText ( 'Data 1 | Data 2' ) ) . toBeDefined ( )
496+ } )
497+
498+ it ( 'handles escaped pipes in table cells' , ( ) => {
499+ const text = '| Header \\| 1 | Header 2 |\n|----------|----------|\n| Cell with \\| escaped pipe | Normal cell |'
500+ const { getByText, getByRole } = render ( < Markdown text = { text } /> )
501+ expect ( getByRole ( 'table' ) ) . toBeDefined ( )
502+ expect ( getByText ( 'Header | 1' ) ) . toBeDefined ( )
503+ expect ( getByText ( 'Header 2' ) ) . toBeDefined ( )
504+ expect ( getByText ( 'Cell with | escaped pipe' ) ) . toBeDefined ( )
505+ expect ( getByText ( 'Normal cell' ) ) . toBeDefined ( )
506+ } )
481507} )
0 commit comments