Skip to content
Merged
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 13 additions & 2 deletions ui/src/common/Markdown.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,17 @@
import React from 'react';
import ReactMarkdown from 'react-markdown';
import ReactMarkdown, {defaultUrlTransform} from 'react-markdown';
import type {UrlTransform} from 'react-markdown';
import gfm from 'remark-gfm';

// Copy from mlflow/server/js/src/shared/web-shared/genai-markdown-renderer/GenAIMarkdownRenderer.tsx
// Related PR: https://github.com/mlflow/mlflow/pull/16761
const urlTransform: UrlTransform = (value) => {
if (value.startsWith('data:image/png;') || value.startsWith('data:image/jpeg;')) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the gotify/android we support a few more formats, maybe we could add image/gif here too? This seems like a commonly used format. For the rest we can wait until someone reports an issue.

return value;
}
return defaultUrlTransform(value);
};

export const Markdown = ({
children,
onImageLoaded = () => {},
Expand All @@ -11,7 +21,8 @@ export const Markdown = ({
}) => (
<ReactMarkdown
components={{img: ({...props}) => <img onLoad={onImageLoaded} {...props} />}}
remarkPlugins={[gfm]}>
remarkPlugins={[gfm]}
urlTransform={urlTransform}>
{children}
</ReactMarkdown>
);
Loading