MCPcopy Create free account
hub / github.com/ChatLab/ChatLab / formatAsMarkdown

Function formatAsMarkdown

src/utils/conversationExport.ts:66–97  ·  view source on GitHub ↗
(
  title: string,
  messages: ExportMessage[],
  createdAt: number,
  labels: ExportLabels
)

Source from the content-addressed store, hash-verified

64 * 格式化对话为 Markdown 格式
65 */
66export function formatAsMarkdown(
67 title: string,
68 messages: ExportMessage[],
69 createdAt: number,
70 labels: ExportLabels
71): string {
72 const lines: string[] = []
73
74 // 标题
75 lines.push(`# ${title}`)
76 lines.push('')
77 lines.push(`> ${labels.createdAt}: ${dayjs(createdAt).format('YYYY-MM-DD HH:mm:ss')}`)
78 lines.push('')
79 lines.push('---')
80 lines.push('')
81
82 // 消息
83 for (const msg of messages) {
84 const time = dayjs(msg.timestamp).format('YYYY-MM-DD HH:mm:ss')
85 const roleLabel = msg.role === 'user' ? labels.user : labels.assistant
86
87 lines.push(`### ${roleLabel}`)
88 lines.push(`*${time}*`)
89 lines.push('')
90 lines.push(msg.content)
91 lines.push('')
92 lines.push('---')
93 lines.push('')
94 }
95
96 return lines.join('\n')
97}
98
99/**
100 * 格式化对话为纯文本格式

Callers 1

exportConversationFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected