@@ -17,7 +17,12 @@ import "prismjs/components/prism-typescript";
17
17
import { renderers } from "../../components/renderers" ;
18
18
import { DEFAULT_MARKDOWN } from "../../constants" ;
19
19
import { Markdown } from "../Markdown" ;
20
- import type { DangerouslyHighlightCode , GetCodeLanguage } from "../renderers" ;
20
+ import {
21
+ DangerouslyHighlightCode ,
22
+ DEFAULT_MARKDOWN_OPTIONS ,
23
+ GetCodeLanguage ,
24
+ MarkdownOptions ,
25
+ } from "../renderers" ;
21
26
22
27
const HEADING_MARKDOWN = `
23
28
# Heading 1
@@ -85,15 +90,31 @@ _Using Single Underscore_
85
90
` ;
86
91
87
92
const BOLD_TEXT_MARKDOWN = `
88
- ___Using Triple Underscore____
93
+ __Using Double Underscore___
89
94
90
- *** Using Triple Asterisk* **
95
+ **Using Double Asterisk**
91
96
` ;
92
97
93
98
const STRIKETHROUGH_TEXT_MARKDOWN = `
94
99
~~This text has strikethroughs~~
95
100
` ;
96
101
102
+ const EMPHASIS_BOLD_STRIKETHROUGH_TEXT_MARKDOWN = `
103
+ ___Should be emphasis and bold.___
104
+
105
+ ***Should be emphasis and bold.***
106
+
107
+ *__Should be emphasis and bold.__*
108
+
109
+ __*Should be emphasis and bold.*__
110
+
111
+ _**Should be emphasis and bold.**_
112
+
113
+ **_Should be emphasis and bold._**
114
+
115
+ ~~**_Should be emphasis, bold, and strikethrough._**~~
116
+ ` ;
117
+
97
118
const ESCAPED_MARKDOWN = `
98
119
Here is some \\* escaped \\* stuff.
99
120
` ;
@@ -181,6 +202,20 @@ Content Cell | Content Cell
181
202
| Content Cell | Content Cell |
182
203
` ;
183
204
205
+ // https://docs.github.com/en/github/writing-on-github/working-with-advanced-formatting/organizing-information-with-tables
206
+ const TABLE_COMPLEX_MARKDOWN = `
207
+ | Left-aligned | Center-aligned | Right-aligned |
208
+ | :--- | :---: | ---: |
209
+ | \`git status\` | List all *new or modified* files |
210
+ | \`git diff\` | Show file differences that **haven't been** staged |
211
+
212
+
213
+ | Name | Character |
214
+ | --- | --- |
215
+ | Backtick | \` |
216
+ | Pipe | \\| |
217
+ ` ;
218
+
184
219
const FOLDABLE_TEXT_MARKDOWN = `
185
220
<details>
186
221
<summary>Title 1</summary>
@@ -193,8 +228,8 @@ const FOLDABLE_TEXT_MARKDOWN = `
193
228
` ;
194
229
195
230
describe ( "Markdown" , ( ) => {
196
- it ( "should be able to render all six heading types" , ( ) => {
197
- const { container, getByRole } = render (
231
+ it ( "should be able to render all six heading types with or without ids " , ( ) => {
232
+ const { container, getByRole, rerender } = render (
198
233
< Markdown markdown = { HEADING_MARKDOWN } />
199
234
) ;
200
235
const heading1 = getByRole ( "heading" , { name : "Heading 1" } ) ;
@@ -205,16 +240,40 @@ describe("Markdown", () => {
205
240
const heading6 = getByRole ( "heading" , { name : "Heading 6" } ) ;
206
241
207
242
expect ( heading1 . tagName ) . toBe ( "H1" ) ;
243
+ expect ( heading1 ) . toHaveAttribute ( "id" , "heading-1" ) ;
208
244
expect ( heading2 . tagName ) . toBe ( "H2" ) ;
245
+ expect ( heading2 ) . toHaveAttribute ( "id" , "heading-2" ) ;
209
246
expect ( heading3 . tagName ) . toBe ( "H3" ) ;
247
+ expect ( heading3 ) . toHaveAttribute ( "id" , "heading-3" ) ;
210
248
expect ( heading4 . tagName ) . toBe ( "H4" ) ;
249
+ expect ( heading4 ) . toHaveAttribute ( "id" , "heading-4" ) ;
211
250
expect ( heading5 . tagName ) . toBe ( "H5" ) ;
251
+ expect ( heading5 ) . toHaveAttribute ( "id" , "heading-5" ) ;
212
252
expect ( heading6 . tagName ) . toBe ( "H6" ) ;
253
+ expect ( heading6 ) . toHaveAttribute ( "id" , "heading-6" ) ;
254
+ expect ( container ) . toMatchSnapshot ( ) ;
213
255
256
+ const options : MarkdownOptions = {
257
+ ...DEFAULT_MARKDOWN_OPTIONS ,
258
+ headerIds : false ,
259
+ } ;
260
+ rerender ( < Markdown options = { options } markdown = { HEADING_MARKDOWN } /> ) ;
261
+ expect ( heading1 . tagName ) . toBe ( "H1" ) ;
262
+ expect ( heading1 ) . not . toHaveAttribute ( "id" ) ;
263
+ expect ( heading2 . tagName ) . toBe ( "H2" ) ;
264
+ expect ( heading2 ) . not . toHaveAttribute ( "id" ) ;
265
+ expect ( heading3 . tagName ) . toBe ( "H3" ) ;
266
+ expect ( heading3 ) . not . toHaveAttribute ( "id" ) ;
267
+ expect ( heading4 . tagName ) . toBe ( "H4" ) ;
268
+ expect ( heading4 ) . not . toHaveAttribute ( "id" ) ;
269
+ expect ( heading5 . tagName ) . toBe ( "H5" ) ;
270
+ expect ( heading5 ) . not . toHaveAttribute ( "id" ) ;
271
+ expect ( heading6 . tagName ) . toBe ( "H6" ) ;
272
+ expect ( heading6 ) . not . toHaveAttribute ( "id" ) ;
214
273
expect ( container ) . toMatchSnapshot ( ) ;
215
274
} ) ;
216
275
217
- it ( "should be able to rendering h1 elements with equal signs" , ( ) => {
276
+ it ( "should be able to render h1 elements with equal signs" , ( ) => {
218
277
const { container, getByRole } = render (
219
278
< Markdown markdown = { HEADING_1_WITH_EQUALS_MARKDOWN } />
220
279
) ;
@@ -229,7 +288,7 @@ describe("Markdown", () => {
229
288
expect ( container ) . toMatchSnapshot ( ) ;
230
289
} ) ;
231
290
232
- it ( "should be able to rendering h1 elements with hyphens" , ( ) => {
291
+ it ( "should be able to render h2 elements with hyphens" , ( ) => {
233
292
const { container, getByRole } = render (
234
293
< Markdown markdown = { HEADING_2_WITH_HYPHENS_MARKDOWN } />
235
294
) ;
@@ -298,15 +357,18 @@ describe("Markdown", () => {
298
357
299
358
it ( "should be able to render blockquotes" , ( ) => {
300
359
const { container } = render ( < Markdown markdown = { BLOCKQUOTE_MARKDOWN } /> ) ;
301
- expect ( container ) . toMatchSnapshot ( ) ;
302
360
expect ( document . querySelector ( "blockquote" ) ) . toBeInTheDocument ( ) ;
361
+ expect ( container ) . toMatchSnapshot ( ) ;
303
362
} ) ;
304
363
305
364
it ( "should be able to render nested blockquotes" , ( ) => {
306
365
const { container } = render (
307
366
< Markdown markdown = { NESTED_BLOCKQUOTE_MARKDOWN } />
308
367
) ;
309
368
expect ( document . querySelectorAll ( "blockquote" ) ?. length ) . toBe ( 2 ) ;
369
+ expect (
370
+ document . querySelector ( "blockquote" ) ?. querySelector ( "blockquote" )
371
+ ) . not . toBe ( null ) ;
310
372
311
373
expect ( container ) . toMatchSnapshot ( ) ;
312
374
} ) ;
@@ -336,6 +398,13 @@ describe("Markdown", () => {
336
398
expect ( container ) . toMatchSnapshot ( ) ;
337
399
} ) ;
338
400
401
+ it ( "should be able to render text that combines emphasis, strong, and strikethrough text" , ( ) => {
402
+ const { container } = render (
403
+ < Markdown markdown = { EMPHASIS_BOLD_STRIKETHROUGH_TEXT_MARKDOWN } />
404
+ ) ;
405
+ expect ( container ) . toMatchSnapshot ( ) ;
406
+ } ) ;
407
+
339
408
it ( "should be able to render escaped (backslash-prefixed) text" , ( ) => {
340
409
const { container } = render ( < Markdown markdown = { ESCAPED_MARKDOWN } /> ) ;
341
410
@@ -504,6 +573,13 @@ describe("Markdown", () => {
504
573
const { container } = render ( < Markdown markdown = { TABLE_MARKDOWN } /> ) ;
505
574
expect ( container ) . toMatchSnapshot ( ) ;
506
575
} ) ;
576
+
577
+ it ( "should be able to render tables with complex markdown" , ( ) => {
578
+ const { container } = render (
579
+ < Markdown markdown = { TABLE_COMPLEX_MARKDOWN } />
580
+ ) ;
581
+ expect ( container ) . toMatchSnapshot ( ) ;
582
+ } ) ;
507
583
} ) ;
508
584
509
585
// TODO: Eventually support this out of the box. It is unsupported right now
0 commit comments