优化markdown渲染

This commit is contained in:
2025-12-29 19:06:45 +08:00
parent 4b6cb726d2
commit d0f133613d
4 changed files with 46 additions and 20 deletions

View File

@@ -329,6 +329,7 @@
flex-direction: row;
align-items: flex-start;
gap: 16rpx;
width: 100%;
}
.other-row {
@@ -363,12 +364,13 @@
.message-content {
display: flex;
flex-direction: column;
max-width: 480rpx;
max-width: 70%;
min-width: 0; // 允许flex子元素收缩
}
// 会议卡片需要更宽的空间
.message-content.meeting-card-wrapper {
max-width: 600rpx;
max-width: 80%;
}
.self-row .message-content {
@@ -382,11 +384,13 @@
}
.bubble {
max-width: 480rpx;
max-width: 100%;
padding: 18rpx 20rpx;
border-radius: 18rpx;
font-size: 28rpx;
line-height: 1.6;
word-break: break-all; // 长单词/URL换行
overflow-wrap: break-word;
}
.other-bubble {
@@ -403,6 +407,15 @@
font-size: 28rpx;
line-height: 1.6;
white-space: pre-wrap;
word-break: break-all;
display: block;
}
.message-rich-text {
font-size: 28rpx;
line-height: 1.6;
word-break: break-all;
overflow-wrap: break-word;
}
.message-time {

View File

@@ -470,10 +470,10 @@ function renderMarkdown(text: string): string {
html = html.replace(/(?<!\*)\*([^\*]+)\*(?!\*)/g, '<em>$1</em>')
// 处理行内代码(`语法)
html = html.replace(/`([^`]+)`/g, '<code style="background-color:#f5f5f5;padding:2px 6px;border-radius:3px;font-family:monospace;color:#e53e3e;">$1</code>')
html = html.replace(/`([^`]+)`/g, '<code style="background-color:#f5f5f5;padding:2px 6px;border-radius:3px;font-family:monospace;color:#e53e3e;word-break:break-all;">$1</code>')
// 处理链接([text](url)语法)
html = html.replace(/\[([^\]]+)\]\(([^)]+)\)/g, '<a href="$2" style="color:#0055AA;text-decoration:underline;">$1</a>')
html = html.replace(/\[([^\]]+)\]\(([^)]+)\)/g, '<a href="$2" style="color:#0055AA;text-decoration:underline;word-break:break-all;">$1</a>')
// 处理标题(# ## ###等)
html = html.replace(/^### (.+)$/gm, '<div style="font-size:16px;font-weight:600;margin:8px 0 4px;">$1</div>')
@@ -486,7 +486,8 @@ function renderMarkdown(text: string): string {
// 处理换行
html = html.replace(/\n/g, '<br/>')
return html
// 包裹在带有换行样式的容器中
return `<div style="word-break:break-all;overflow-wrap:break-word;white-space:pre-wrap;">${html}</div>`
}
// 发送消息