@@ -180,6 +180,7 @@ type MarkdownProps = {
180
180
onClickExecute ?: ( cmd : string ) => void ;
181
181
resolveOpts ?: MarkdownResolveOpts ;
182
182
scrollable ?: boolean ;
183
+ rehype ?: boolean ;
183
184
} ;
184
185
185
186
const Markdown = ( {
@@ -190,6 +191,7 @@ const Markdown = ({
190
191
className,
191
192
resolveOpts,
192
193
scrollable = true ,
194
+ rehype = true ,
193
195
onClickExecute,
194
196
} : MarkdownProps ) => {
195
197
const textAtomValue = useAtomValueSafe < string > ( textAtom ) ;
@@ -250,6 +252,29 @@ const Markdown = ({
250
252
} , [ showToc , tocRef ] ) ;
251
253
252
254
text = textAtomValue ?? text ;
255
+ let rehypePlugins = null ;
256
+ if ( rehype ) {
257
+ rehypePlugins = [
258
+ rehypeRaw ,
259
+ rehypeHighlight ,
260
+ ( ) =>
261
+ rehypeSanitize ( {
262
+ ...defaultSchema ,
263
+ attributes : {
264
+ ...defaultSchema . attributes ,
265
+ span : [
266
+ ...( defaultSchema . attributes ?. span || [ ] ) ,
267
+ // Allow all class names starting with `hljs-`.
268
+ [ "className" , / ^ h l j s - ./ ] ,
269
+ // Alternatively, to allow only certain class names:
270
+ // ['className', 'hljs-number', 'hljs-title', 'hljs-variable']
271
+ ] ,
272
+ } ,
273
+ tagNames : [ ...( defaultSchema . tagNames || [ ] ) , "span" ] ,
274
+ } ) ,
275
+ ( ) => rehypeSlug ( { prefix : idPrefix } ) ,
276
+ ] ;
277
+ }
253
278
254
279
const ScrollableMarkdown = ( ) => {
255
280
return (
@@ -260,26 +285,7 @@ const Markdown = ({
260
285
>
261
286
< ReactMarkdown
262
287
remarkPlugins = { [ remarkGfm , remarkAlert , [ RemarkFlexibleToc , { tocRef : tocRef . current } ] ] }
263
- rehypePlugins = { [
264
- rehypeRaw ,
265
- rehypeHighlight ,
266
- ( ) =>
267
- rehypeSanitize ( {
268
- ...defaultSchema ,
269
- attributes : {
270
- ...defaultSchema . attributes ,
271
- span : [
272
- ...( defaultSchema . attributes ?. span || [ ] ) ,
273
- // Allow all class names starting with `hljs-`.
274
- [ "className" , / ^ h l j s - ./ ] ,
275
- // Alternatively, to allow only certain class names:
276
- // ['className', 'hljs-number', 'hljs-title', 'hljs-variable']
277
- ] ,
278
- } ,
279
- tagNames : [ ...( defaultSchema . tagNames || [ ] ) , "span" ] ,
280
- } ) ,
281
- ( ) => rehypeSlug ( { prefix : idPrefix } ) ,
282
- ] }
288
+ rehypePlugins = { rehypePlugins }
283
289
components = { markdownComponents }
284
290
>
285
291
{ text }
@@ -293,26 +299,7 @@ const Markdown = ({
293
299
< div className = "content non-scrollable" >
294
300
< ReactMarkdown
295
301
remarkPlugins = { [ remarkGfm , [ RemarkFlexibleToc , { tocRef : tocRef . current } ] ] }
296
- rehypePlugins = { [
297
- rehypeRaw ,
298
- rehypeHighlight ,
299
- ( ) =>
300
- rehypeSanitize ( {
301
- ...defaultSchema ,
302
- attributes : {
303
- ...defaultSchema . attributes ,
304
- span : [
305
- ...( defaultSchema . attributes ?. span || [ ] ) ,
306
- // Allow all class names starting with `hljs-`.
307
- [ "className" , / ^ h l j s - ./ ] ,
308
- // Alternatively, to allow only certain class names:
309
- // ['className', 'hljs-number', 'hljs-title', 'hljs-variable']
310
- ] ,
311
- } ,
312
- tagNames : [ ...( defaultSchema . tagNames || [ ] ) , "span" ] ,
313
- } ) ,
314
- ( ) => rehypeSlug ( { prefix : idPrefix } ) ,
315
- ] }
302
+ rehypePlugins = { rehypePlugins }
316
303
components = { markdownComponents }
317
304
>
318
305
{ text }
0 commit comments