Skip to content

Commit 9879280

Browse files
fix: fix markdown embed image issue (#857)
* fix: fix markdown embed image issue * fix urlTransform filter condition * fix code format * add image/gif filter * Format code --------- Co-authored-by: 饺子w (Yumechi) <35571479+eternal-flame-AD@users.noreply.github.com>
1 parent 9703021 commit 9879280

1 file changed

Lines changed: 17 additions & 2 deletions

File tree

‎ui/src/common/Markdown.tsx‎

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,21 @@
11
import React from 'react';
2-
import ReactMarkdown from 'react-markdown';
2+
import ReactMarkdown, {defaultUrlTransform} from 'react-markdown';
3+
import type {UrlTransform} from 'react-markdown';
34
import gfm from 'remark-gfm';
45

6+
// Copy from mlflow/server/js/src/shared/web-shared/genai-markdown-renderer/GenAIMarkdownRenderer.tsx
7+
// Related PR: https://github.com/mlflow/mlflow/pull/16761
8+
const urlTransform: UrlTransform = (value) => {
9+
if (
10+
value.startsWith('data:image/png;') ||
11+
value.startsWith('data:image/jpeg;') ||
12+
value.startsWith('data:image/gif;')
13+
) {
14+
return value;
15+
}
16+
return defaultUrlTransform(value);
17+
};
18+
519
export const Markdown = ({
620
children,
721
onImageLoaded = () => {},
@@ -11,7 +25,8 @@ export const Markdown = ({
1125
}) => (
1226
<ReactMarkdown
1327
components={{img: ({...props}) => <img onLoad={onImageLoaded} {...props} />}}
14-
remarkPlugins={[gfm]}>
28+
remarkPlugins={[gfm]}
29+
urlTransform={urlTransform}>
1530
{children}
1631
</ReactMarkdown>
1732
);

0 commit comments

Comments
 (0)