1
1
import { Fragment , ReactNode , useContext , useMemo , useState } from 'react'
2
- import { compact , isNil } from 'lodash-es'
2
+ import { compact , flatten , isNil } from 'lodash-es'
3
3
import rehypeRaw from 'rehype-raw'
4
4
import rehypeSanitize , { defaultSchema } from 'rehype-sanitize'
5
5
import remarkGfm from 'remark-gfm'
@@ -21,7 +21,7 @@ import {
21
21
convertFromFilepath ,
22
22
convertToFilepath ,
23
23
encodeMentionPlaceHolder ,
24
- formatMarkdownCustomTags ,
24
+ formatCustomHTMLBlockTags ,
25
25
getRangeFromAttachmentCode ,
26
26
resolveFileNameForDisplay
27
27
} from '@/lib/utils'
@@ -43,7 +43,10 @@ import {
43
43
SymbolInfo
44
44
} from 'tabby-chat-panel/index'
45
45
46
- import { MARKDOWN_CUSTOM_TAGS } from '@/lib/constants'
46
+ import {
47
+ CUSTOM_HTML_BLOCK_TAGS ,
48
+ CUSTOM_HTML_INLINE_TAGS
49
+ } from '@/lib/constants'
47
50
import {
48
51
MARKDOWN_CITATION_REGEX ,
49
52
MARKDOWN_COMMAND_REGEX ,
@@ -277,8 +280,11 @@ export function MessageMarkdown({
277
280
}
278
281
279
282
const encodedMessage = useMemo ( ( ) => {
280
- const formatedMessage = formatMarkdownCustomTags ( message )
281
- return encodeMentionPlaceHolder ( formatedMessage )
283
+ const formattedMessage = formatCustomHTMLBlockTags (
284
+ message ,
285
+ CUSTOM_HTML_BLOCK_TAGS as unknown as string [ ]
286
+ )
287
+ return encodeMentionPlaceHolder ( formattedMessage )
282
288
} , [ message ] )
283
289
284
290
return (
@@ -310,16 +316,25 @@ export function MessageMarkdown({
310
316
) }
311
317
remarkPlugins = { [ remarkGfm , remarkMath ] }
312
318
rehypePlugins = { [
313
- customStripTagsPlugin ,
319
+ [
320
+ customStripTagsPlugin ,
321
+ {
322
+ tagNames : flatten ( [
323
+ CUSTOM_HTML_BLOCK_TAGS ,
324
+ CUSTOM_HTML_INLINE_TAGS
325
+ ] )
326
+ }
327
+ ] ,
314
328
rehypeRaw ,
315
329
[
316
330
rehypeSanitize ,
317
331
{
318
332
...defaultSchema ,
319
- tagNames : [
320
- ...( defaultSchema . tagNames ?? [ ] ) ,
321
- ...MARKDOWN_CUSTOM_TAGS
322
- ]
333
+ tagNames : flatten ( [
334
+ defaultSchema . tagNames ,
335
+ CUSTOM_HTML_BLOCK_TAGS ,
336
+ CUSTOM_HTML_INLINE_TAGS
337
+ ] )
323
338
}
324
339
]
325
340
] }
0 commit comments