File tree Expand file tree Collapse file tree 3 files changed +48
-0
lines changed Expand file tree Collapse file tree 3 files changed +48
-0
lines changed Original file line number Diff line number Diff line change @@ -121,6 +121,14 @@ Here is some \\*escaped\\* stuff.
121
121
Allow \\_\\_tests\\_\\_.
122
122
` ;
123
123
124
+ const ESCAPED_HTML_MARKDOWN = `
125
+ - \\<img>
126
+ - \\<video>
127
+ - \\<iframe>
128
+ - \\<embed>
129
+ - \\<object>
130
+ ` ;
131
+
124
132
const BR_MARKDOWN = `
125
133
Trailing two spaces to force break
126
134
Second Line of text with trailing slash to force break\\
@@ -426,6 +434,14 @@ describe("Markdown", () => {
426
434
expect ( container ) . toMatchSnapshot ( ) ;
427
435
} ) ;
428
436
437
+ it ( "should be able to render escaped (backslash-prefixed) html" , ( ) => {
438
+ const { container } = render ( < Markdown markdown = { ESCAPED_HTML_MARKDOWN } /> ) ;
439
+ const firstLi = document . querySelector ( "li" ) ;
440
+ expect ( firstLi ?. innerHTML ) . toBe ( "<img>" ) ;
441
+
442
+ expect ( container ) . toMatchSnapshot ( ) ;
443
+ } ) ;
444
+
429
445
it ( "should be able to render breaks (<br>)" , ( ) => {
430
446
const { container } = render ( < Markdown markdown = { BR_MARKDOWN } /> ) ;
431
447
Original file line number Diff line number Diff line change @@ -201,6 +201,34 @@ exports[`Markdown should be able to render emphasis (italic) text 1`] = `
201
201
</div >
202
202
`;
203
203
204
+ exports[`Markdown should be able to render escaped (backslash-prefixed) html 1`] = `
205
+ <div >
206
+
207
+ <ul >
208
+ <li >
209
+ <
210
+ img>
211
+ </li >
212
+ <li >
213
+ <
214
+ video>
215
+ </li >
216
+ <li >
217
+ <
218
+ iframe>
219
+ </li >
220
+ <li >
221
+ <
222
+ embed>
223
+ </li >
224
+ <li >
225
+ <
226
+ object>
227
+ </li >
228
+ </ul >
229
+ </div >
230
+ `;
231
+
204
232
exports[`Markdown should be able to render escaped (backslash-prefixed) text 1`] = `
205
233
<div >
206
234
Original file line number Diff line number Diff line change @@ -36,6 +36,10 @@ export type EscapeRendererProps = marked.Tokens.Escape;
36
36
* ```
37
37
*/
38
38
export function EscapeRenderer ( { text } : EscapeRendererProps ) : ReactElement {
39
+ if ( text === "<" ) {
40
+ return < > <</ > ;
41
+ }
42
+
39
43
return < > { text } </ > ;
40
44
}
41
45
You can’t perform that action at this time.
0 commit comments