Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { Markdown } from './Markdown';
const mocks = vi.hoisted(() => ({
getCurrentWorkspacePath: vi.fn(),
revealInExplorer: vi.fn(),
readFileContent: vi.fn(),
openExternal: vi.fn(),
renderMath: vi.fn(),
}));
Expand All @@ -19,7 +20,7 @@ vi.mock('../../../infrastructure/api', () => ({
},
workspaceAPI: {
revealInExplorer: (...args: unknown[]) => mocks.revealInExplorer(...args),
readFileContent: vi.fn(),
readFileContent: (...args: unknown[]) => mocks.readFileContent(...args),
},
systemAPI: {
openExternal: (...args: unknown[]) => mocks.openExternal(...args),
Expand Down Expand Up @@ -98,9 +99,11 @@ describe('Markdown file links', () => {
onFileViewRequest = vi.fn();
mocks.getCurrentWorkspacePath.mockReset();
mocks.revealInExplorer.mockReset();
mocks.readFileContent.mockReset();
mocks.openExternal.mockReset();
mocks.renderMath.mockReset();
mocks.getCurrentWorkspacePath.mockResolvedValue(EXAMPLE_WORKSPACE);
mocks.readFileContent.mockResolvedValue('cmVsdS1wbmc=');
});

afterEach(() => {
Expand Down Expand Up @@ -228,4 +231,24 @@ describe('Markdown file links', () => {
expect(container.querySelector('[data-testid="markdown-math-renderer"]')).not.toBeNull();
expect(mocks.renderMath).toHaveBeenCalledWith('Formula: $x + y$');
});

it('loads relative markdown images from the provided base path', async () => {
await act(async () => {
root.render(
<Markdown
content={'![ReLU 图像](relu.png)'}
basePath={EXAMPLE_WORKSPACE}
onFileViewRequest={onFileViewRequest}
/>,
);
await Promise.resolve();
await Promise.resolve();
});

const image = container.querySelector<HTMLImageElement>('img[alt="ReLU 图像"]');
expect(image).not.toBeNull();
expect(mocks.readFileContent).toHaveBeenCalledWith(`${EXAMPLE_WORKSPACE}/relu.png`);
expect(image?.src).toBe('data:image/png;base64,cmVsdS1wbmc=');
expect(mocks.getCurrentWorkspacePath).not.toHaveBeenCalled();
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -811,7 +811,7 @@ export const Markdown = React.memo<MarkdownProps>(({
);

useEffect(() => {
if (!needsWorkspacePathForLinks || currentWorkspacePath) {
if (!needsWorkspacePathForLinks || currentWorkspacePath || basePath) {
return;
}

Expand All @@ -830,7 +830,7 @@ export const Markdown = React.memo<MarkdownProps>(({
return () => {
cancelled = true;
};
}, [currentWorkspacePath, needsWorkspacePathForLinks]);
}, [basePath, currentWorkspacePath, needsWorkspacePathForLinks]);

const markdownFeatureProfile = useMemo(() => ({
contentLength: markdownContent.length,
Expand Down Expand Up @@ -1319,7 +1319,7 @@ export const Markdown = React.memo<MarkdownProps>(({
},

img({ node: _node, ...props }: any) {
return <MarkdownImage {...props} basePath={basePath} />;
return <MarkdownImage {...props} basePath={basePath || currentWorkspacePath} />;
},

blockquote({ children }: any) {
Expand Down
4 changes: 4 additions & 0 deletions src/web-ui/src/flow_chat/components/FlowTextBlock.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,10 @@ export const FlowTextBlock = React.memo<FlowTextBlockProps>(({
onTabOpen,
onHttpLinkClick,
onOpenVisualization,
activeSessionOverride,
} = useFlowChatContext();
const markdownBasePath = activeSessionOverride?.workspacePath
|| activeSessionOverride?.config?.workspacePath;

// Normalize content to a string.
const content = typeof textItem.content === 'string'
Expand Down Expand Up @@ -147,6 +150,7 @@ export const FlowTextBlock = React.memo<FlowTextBlockProps>(({
{textItem.isMarkdown ? (
<MarkdownRenderer
content={displayContent}
basePath={markdownBasePath}
// Pass the raw streaming flag (not the idle-gated
// `isActivelyStreaming`) so the code-block render path inside
// Markdown stays stable across bursty AI output. Otherwise
Expand Down
Loading