MCPcopy Index your code
hub / github.com/codeaashu/claude-code / renderMessage

Function renderMessage

web/lib/export/markdown.ts:4–47  ·  view source on GitHub ↗
(msg: Message, options: ExportOptions)

Source from the content-addressed store, hash-verified

2import { extractTextContent } from "../utils";
3
4function renderMessage(msg: Message, options: ExportOptions): string {
5 const parts: string[] = [];
6
7 const roleLabel =
8 msg.role === "user"
9 ? "**User**"
10 : msg.role === "assistant"
11 ? "**Assistant**"
12 : `**${msg.role}**`;
13
14 parts.push(`### ${roleLabel}`);
15
16 if (options.includeTimestamps) {
17 parts.push(`_${new Date(msg.createdAt).toLocaleString()}_\n`);
18 }
19
20 if (typeof msg.content === "string") {
21 parts.push(msg.content);
22 } else {
23 for (const block of msg.content) {
24 if (block.type === "text") {
25 parts.push(block.text);
26 } else if (block.type === "tool_use" && options.includeToolUse) {
27 parts.push(
28 `\`\`\`tool-use\n// Tool: ${block.name}\n${JSON.stringify(block.input, null, 2)}\n\`\`\``
29 );
30 } else if (block.type === "tool_result" && options.includeToolUse) {
31 const raw =
32 typeof block.content === "string"
33 ? block.content
34 : extractTextContent(block.content);
35 const truncated =
36 !options.includeFileContents && raw.length > 500
37 ? raw.slice(0, 500) + "\n…[truncated]"
38 : raw;
39 parts.push(
40 `\`\`\`tool-result${block.is_error ? " error" : ""}\n${truncated}\n\`\`\``
41 );
42 }
43 }
44 }
45
46 return parts.join("\n\n");
47}
48
49export function toMarkdown(conv: Conversation, options: ExportOptions): string {
50 const lines: string[] = [

Callers 1

toMarkdownFunction · 0.85

Calls 2

extractTextContentFunction · 0.90
pushMethod · 0.45

Tested by

no test coverage detected