Skip to content
Open
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
7 changes: 7 additions & 0 deletions canvas/src/markdown.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,13 @@ describe("renderMarkdown", () => {
expect(renderMarkdown("run `bun test")).toContain("<code>bun test</code>");
});

it("draws no picture until its source has arrived whole", () => {
expect(renderMarkdown("see ![shot](https://x.dev/a")).not.toContain("<img");
expect(renderMarkdown("see ![shot](https://x.dev/a.png)")).toContain(
'src="https://x.dev/a.png"',
);
});

it("is a table only once the delimiter row has arrived", () => {
expect(renderMarkdown("| a | b |")).not.toContain("<table");
expect(renderMarkdown("| a | b |\n| - | - |")).toContain("<table");
Expand Down
7 changes: 6 additions & 1 deletion canvas/src/markdown.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
*/
import DOMPurify from "dompurify";
import { Marked } from "marked";
import remend from "remend";
import remend, { INCOMPLETE_IMAGE_PLACEHOLDER } from "remend";

// The agent links what it made as `file:///鈥, which DOMPurify drops and an http page could not
// follow anyway. Relative to the project's page, `file/<path>` is the project's server
Expand All @@ -21,6 +21,11 @@ const md = new Marked({
token.href = `file${url.pathname}${url.search}${url.hash}`;
}
},
// A picture a delta cut open comes out of remend under a source only Streamdown draws, which
// DOMPurify drops, leaving an `<img>` with none. Nothing is drawn until the rest arrives.
renderer: {
image: ({ href }) => (href === INCOMPLETE_IMAGE_PLACEHOLDER ? "" : false),

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

馃攳 Streaming image change lacks release note

The renderer changes what users see, but ## Unreleased has no entry. Contributing rules require one for user-visible changes; the author says no released install had the regression.

Devin Review


Was this helpful? React with 馃憤 or 馃憥 to provide feedback.

},
});

export function renderMarkdown(text: string): string {
Expand Down
Loading