Skip to content

Commit

Permalink
Enforce max image size for markdown
Browse files Browse the repository at this point in the history
  • Loading branch information
chrismaltais committed May 23, 2024
1 parent 818f1b3 commit 74d70c6
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 3 deletions.
23 changes: 23 additions & 0 deletions src/web/nextui/src/app/components/CustomImage.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import Image from 'next/image';
import React from 'react';

interface CustomImageProps {
src: string;
alt: string;
title?: string;
}

const CustomImage: React.FC<CustomImageProps> = ({ src, alt, title }) => {
const width = 400;
return (
<Image
src={src}
alt={alt}
title={title}
width={width}
style={{ maxWidth: '100%', height: 'auto' }} // Ensure responsiveness
/>
);
};

export default CustomImage;
23 changes: 23 additions & 0 deletions src/web/nextui/src/app/components/MarkdownRenderer.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import React from 'react';
import ReactMarkdown from 'react-markdown';
import CustomImage from './CustomImage';

interface MarkdownRendererProps {
content: string;
}

const MarkdownRenderer: React.FC<MarkdownRendererProps> = ({ content }) => {
return (
<ReactMarkdown
components={{
img: ({ node, ...props }) => (
<CustomImage src={props.src || ''} alt={props.alt || ''} {...props} />
),
}}
>
{content}
</ReactMarkdown>
);
};

export default MarkdownRenderer;
6 changes: 3 additions & 3 deletions src/web/nextui/src/app/eval/ResultsTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { diffSentences, diffJson, diffWords } from 'diff';

import './index.css';

import ReactMarkdown from 'react-markdown';
import MarkdownRenderer from '@/app/components/MarkdownRenderer';
import invariant from 'tiny-invariant';
import {
createColumnHelper,
Expand Down Expand Up @@ -299,7 +299,7 @@ function EvalOutputCell({
console.error('Invalid regular expression:', (error as Error).message);
}
} else if (renderMarkdown) {
node = <ReactMarkdown>{text}</ReactMarkdown>;
node = <MarkdownRenderer content={text} />
} else if (prettifyJson) {
try {
node = <pre>{JSON.stringify(JSON.parse(text), null, 2)}</pre>;
Expand Down Expand Up @@ -749,7 +749,7 @@ function ResultsTable({
return (
<div className="cell">
{renderMarkdown ? (
<ReactMarkdown>{value}</ReactMarkdown>
<MarkdownRenderer content={value} />
) : (
<MemoizedTruncatedText text={value} maxLength={maxTextLength} />
)}
Expand Down

0 comments on commit 74d70c6

Please sign in to comment.