-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Fixes #4787: Enable markdown table rendering #4790
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
20 changes: 20 additions & 0 deletions
20
webview-ui/src/components/common/__tests__/MarkdownBlock.simple.test.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| import "@testing-library/jest-dom" | ||
|
|
||
| // Simple test to verify the fix works | ||
| describe("MarkdownBlock Table Fix", () => { | ||
| it("should now use the real remark-gfm plugin", async () => { | ||
| // This test verifies that the real remark-gfm plugin is now being used | ||
| // (no more mock blocking it) | ||
| const { default: remarkGfm } = await import("remark-gfm") | ||
|
|
||
| // The real plugin should be a proper function | ||
| expect(typeof remarkGfm).toBe("function") | ||
|
|
||
| // The function should not be an empty mock function | ||
| expect(remarkGfm.toString()).not.toBe("() => {}") | ||
| expect(remarkGfm.toString()).not.toBe("function () { }") | ||
|
|
||
| // This confirms that the real remark-gfm plugin is now available, | ||
| // which should enable proper table rendering | ||
| }) | ||
| }) |
137 changes: 137 additions & 0 deletions
137
webview-ui/src/components/common/__tests__/MarkdownBlock.table.test.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,137 @@ | ||
| import React from "react" | ||
| import { render, screen } from "@testing-library/react" | ||
| import "@testing-library/jest-dom" | ||
| import MarkdownBlock from "../MarkdownBlock" | ||
| import { ExtensionStateContextProvider } from "@src/context/ExtensionStateContext" | ||
|
|
||
| // Mock the vscode module | ||
| jest.mock("@src/utils/vscode", () => ({ | ||
| vscode: { | ||
| postMessage: jest.fn(), | ||
| }, | ||
| })) | ||
|
|
||
| // Create a test wrapper with the required context | ||
| const TestWrapper = ({ children }: { children: React.ReactNode }) => { | ||
| return <ExtensionStateContextProvider>{children}</ExtensionStateContextProvider> | ||
| } | ||
|
|
||
| describe("MarkdownBlock Table Rendering", () => { | ||
| it("should render markdown tables as HTML tables", async () => { | ||
| const markdownWithTable = ` | ||
| # Test Document | ||
|
|
||
| Here's a test table: | ||
|
|
||
| | Name | Age | City | | ||
| |------|-----|------| | ||
| | John | 25 | NYC | | ||
| | Jane | 30 | LA | | ||
| | Bob | 35 | Chicago | | ||
|
|
||
| End of document. | ||
| ` | ||
|
|
||
| render( | ||
| <TestWrapper> | ||
| <MarkdownBlock markdown={markdownWithTable} /> | ||
| </TestWrapper>, | ||
| ) | ||
|
|
||
| // Wait for the component to render | ||
| await screen.findByText("Test Document") | ||
|
|
||
| // Check that table elements are rendered | ||
| const table = screen.getByRole("table") | ||
| expect(table).toBeInTheDocument() | ||
|
|
||
| // Check for table headers | ||
| expect(screen.getByRole("columnheader", { name: "Name" })).toBeInTheDocument() | ||
| expect(screen.getByRole("columnheader", { name: "Age" })).toBeInTheDocument() | ||
| expect(screen.getByRole("columnheader", { name: "City" })).toBeInTheDocument() | ||
|
|
||
| // Check for table data | ||
| expect(screen.getByRole("cell", { name: "John" })).toBeInTheDocument() | ||
| expect(screen.getByRole("cell", { name: "25" })).toBeInTheDocument() | ||
| expect(screen.getByRole("cell", { name: "NYC" })).toBeInTheDocument() | ||
| expect(screen.getByRole("cell", { name: "Jane" })).toBeInTheDocument() | ||
| expect(screen.getByRole("cell", { name: "30" })).toBeInTheDocument() | ||
| expect(screen.getByRole("cell", { name: "LA" })).toBeInTheDocument() | ||
| expect(screen.getByRole("cell", { name: "Bob" })).toBeInTheDocument() | ||
| expect(screen.getByRole("cell", { name: "35" })).toBeInTheDocument() | ||
| expect(screen.getByRole("cell", { name: "Chicago" })).toBeInTheDocument() | ||
| }) | ||
|
|
||
| it("should render tables with proper styling", async () => { | ||
| const markdownWithTable = ` | ||
| | Header 1 | Header 2 | | ||
| |----------|----------| | ||
| | Cell 1 | Cell 2 | | ||
| ` | ||
|
|
||
| render( | ||
| <TestWrapper> | ||
| <MarkdownBlock markdown={markdownWithTable} /> | ||
| </TestWrapper>, | ||
| ) | ||
|
|
||
| const table = await screen.findByRole("table") | ||
| expect(table).toBeInTheDocument() | ||
|
|
||
| // Check that the table has the expected structure | ||
| const headers = screen.getAllByRole("columnheader") | ||
| expect(headers).toHaveLength(2) | ||
|
|
||
| const cells = screen.getAllByRole("cell") | ||
| expect(cells).toHaveLength(2) | ||
| }) | ||
|
|
||
| it("should handle empty tables gracefully", async () => { | ||
| const markdownWithEmptyTable = ` | ||
| | Header 1 | Header 2 | | ||
| |----------|----------| | ||
| ` | ||
|
|
||
| render( | ||
| <TestWrapper> | ||
| <MarkdownBlock markdown={markdownWithEmptyTable} /> | ||
| </TestWrapper>, | ||
| ) | ||
|
|
||
| const table = await screen.findByRole("table") | ||
| expect(table).toBeInTheDocument() | ||
|
|
||
| // Should have headers but no data rows | ||
| const headers = screen.getAllByRole("columnheader") | ||
| expect(headers).toHaveLength(2) | ||
|
|
||
| const cells = screen.queryAllByRole("cell") | ||
| expect(cells).toHaveLength(0) | ||
| }) | ||
|
|
||
| it("should not render raw markdown table syntax", async () => { | ||
| const markdownWithTable = ` | ||
| | Name | Age | | ||
| |------|-----| | ||
| | John | 25 | | ||
| ` | ||
|
|
||
| render( | ||
| <TestWrapper> | ||
| <MarkdownBlock markdown={markdownWithTable} /> | ||
| </TestWrapper>, | ||
| ) | ||
|
|
||
| // Should not contain raw markdown table syntax | ||
| expect(screen.queryByText("|------|-----|")).not.toBeInTheDocument() | ||
| expect(screen.queryByText("| Name | Age |")).not.toBeInTheDocument() | ||
| expect(screen.queryByText("| John | 25 |")).not.toBeInTheDocument() | ||
|
|
||
| // Should contain the actual table content | ||
| expect(screen.getByRole("table")).toBeInTheDocument() | ||
| expect(screen.getByRole("columnheader", { name: "Name" })).toBeInTheDocument() | ||
| expect(screen.getByRole("columnheader", { name: "Age" })).toBeInTheDocument() | ||
| expect(screen.getByRole("cell", { name: "John" })).toBeInTheDocument() | ||
| expect(screen.getByRole("cell", { name: "25" })).toBeInTheDocument() | ||
| }) | ||
| }) |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oops - this is the logging from the roomote agent. I'll add this to .gitignore.