feat: render LaTeX, custom HTML and diagrams in the transcript (#19)
This commit was merged in pull request #19.
This commit is contained in:
+10
-7
@@ -1,5 +1,5 @@
|
||||
import { imageSource } from "./attachments";
|
||||
import { repairCodeBlocks } from "./code";
|
||||
import { renderInlineContent, renderModelOutput } from "./render";
|
||||
import { describeActivity } from "./thread";
|
||||
import type { Attachment, ChatTurn, ThreadMessage, ToolCallRecord } from "./types";
|
||||
|
||||
@@ -117,10 +117,13 @@ function renderToolFailureNote(message: ThreadMessage): string | undefined {
|
||||
}
|
||||
|
||||
function renderMessage(message: ThreadMessage, options: TranscriptOptions): string {
|
||||
// The question is identified by its styling alone.
|
||||
// The question is identified by its styling alone. It goes through the same
|
||||
// rendering pass as an answer, because a person pastes LaTeX into a question
|
||||
// as readily as a model writes it, and a question full of raw HTML should be
|
||||
// put behind the same fence.
|
||||
if (message.role === "user") {
|
||||
const images = renderAttachments(message.attachments);
|
||||
const asked = quote(message.text);
|
||||
const asked = quote(renderInlineContent(message.text));
|
||||
|
||||
return images ? `${asked}\n\n${images}` : asked;
|
||||
}
|
||||
@@ -148,10 +151,10 @@ function renderMessage(message: ThreadMessage, options: TranscriptOptions): stri
|
||||
/** The answer, or whatever stands in for it while there is none. */
|
||||
const answered = message.text.trim();
|
||||
const body = answered
|
||||
? // Fences without a language render as a plain dark panel, and a lone
|
||||
// inline command renders as a chip with no Copy button at all. Both are
|
||||
// repaired before the markdown reaches the renderer.
|
||||
repairCodeBlocks(answered)
|
||||
? // One pass, in one place: fences get their languages and links recovered,
|
||||
// then TeX becomes something drawable and the HTML around it is filtered to
|
||||
// the subset the renderer acts on. See `render.ts` for the order and why.
|
||||
renderModelOutput(answered)
|
||||
: !message.isStreaming
|
||||
? "_No response._"
|
||||
: activityLine
|
||||
|
||||
Reference in New Issue
Block a user