|
7 | 7 | imageToLink, |
8 | 8 | keepLineBreaksPlugin, |
9 | 9 | plusPlusToEmphasis, |
| 10 | + remarkIgnoreMarkdown, |
10 | 11 | } from '../remarkPlugins'; |
11 | 12 | import { defaultAllowedTagNames, renderText } from '../renderText'; |
12 | 13 | import '@testing-library/jest-dom'; |
@@ -306,19 +307,19 @@ describe(`renderText`, () => { |
306 | 307 | }); |
307 | 308 | }); |
308 | 309 |
|
309 | | -describe('keepLineBreaksPlugin', () => { |
310 | | - const lineBreaks = '\n\n\n'; |
311 | | - const paragraphText = `a${lineBreaks}b${lineBreaks}c`; |
312 | | - const unorderedListText = `* item 1${lineBreaks}* item 2${lineBreaks}* item 3`; |
313 | | - const orderedListText = `1. item 1${lineBreaks}2. item 2${lineBreaks}3. item 3`; |
314 | | - const headingText = `## Heading${lineBreaks}a`; |
315 | | - const codeBlockText = 'a\n\n\n```b```\n\n\nc'; |
316 | | - const horizontalRuleText = `a${lineBreaks}---${lineBreaks}b`; |
317 | | - const blockquoteText = `a${lineBreaks}>b${lineBreaks}c`; |
318 | | - const withStrikeThroughText = `a${lineBreaks}${strikeThroughText}${lineBreaks}b`; |
319 | | - const tableText = `a${lineBreaks}| a | b | c | d |\n| - | :- | -: | :-: |\n| a | b | c | d |${lineBreaks}c`; |
320 | | - const multilineWithStrongText = 'This is **the first** line\n\nThis is the second line'; |
| 310 | +const lineBreaks = '\n\n\n'; |
| 311 | +const paragraphText = `a${lineBreaks}b${lineBreaks}c`; |
| 312 | +const unorderedListText = `* item 1${lineBreaks}* item 2${lineBreaks}* item 3`; |
| 313 | +const orderedListText = `1. item 1${lineBreaks}2. item 2${lineBreaks}3. item 3`; |
| 314 | +const headingText = `## Heading${lineBreaks}a`; |
| 315 | +const codeBlockText = 'a\n\n\n```b```\n\n\nc'; |
| 316 | +const horizontalRuleText = `a${lineBreaks}---${lineBreaks}b`; |
| 317 | +const blockquoteText = `a${lineBreaks}>b${lineBreaks}c`; |
| 318 | +const withStrikeThroughText = `a${lineBreaks}${strikeThroughText}${lineBreaks}b`; |
| 319 | +const tableText = `a${lineBreaks}| a | b | c | d |\n| - | :- | -: | :-: |\n| a | b | c | d |${lineBreaks}c`; |
| 320 | +const multilineWithStrongText = 'This is **the first** line\n\nThis is the second line'; |
321 | 321 |
|
| 322 | +describe('keepLineBreaksPlugin', () => { |
322 | 323 | const doRenderText = (text, present) => { |
323 | 324 | const Markdown = renderText( |
324 | 325 | text, |
@@ -500,3 +501,37 @@ describe('imageToLink', () => { |
500 | 501 | ).not.toBeInTheDocument(); |
501 | 502 | }); |
502 | 503 | }); |
| 504 | + |
| 505 | +describe('remarkIgnoreMarkdown', () => { |
| 506 | + const text = [ |
| 507 | + headingText, |
| 508 | + paragraphText, |
| 509 | + unorderedListText, |
| 510 | + orderedListText, |
| 511 | + codeBlockText, |
| 512 | + horizontalRuleText, |
| 513 | + blockquoteText, |
| 514 | + withStrikeThroughText, |
| 515 | + tableText, |
| 516 | + multilineWithStrongText, |
| 517 | + ].join('\n'); |
| 518 | + |
| 519 | + const renderWithPlugin = (plugins = []) => { |
| 520 | + const Markdown = renderText( |
| 521 | + text, |
| 522 | + {}, |
| 523 | + { getRemarkPlugins: () => [...plugins, remarkIgnoreMarkdown] }, |
| 524 | + ); |
| 525 | + return render(Markdown).container; |
| 526 | + }; |
| 527 | + |
| 528 | + it('skips the markdown transformation and keeps the original escaped text and lines', () => { |
| 529 | + expect(renderWithPlugin().innerHTML).toBe(`<p>${text.replace(/>/g, '>')}</p>`); |
| 530 | + }); |
| 531 | + |
| 532 | + it('keeps line without keepLineBreaksPlugin', () => { |
| 533 | + expect(renderWithPlugin([keepLineBreaksPlugin]).innerHTML).toBe( |
| 534 | + renderWithPlugin().innerHTML, |
| 535 | + ); |
| 536 | + }); |
| 537 | +}); |
0 commit comments