Skip to content

Go implementation of DeepSeek Harness and self-hosted personal agent.

Go

fix(mobile): restore native inline code layout and trim block spacing

xycad982c407681
diff --git a/docs/markdown-and-demo-refresh-plan.zh-CN.md b/docs/markdown-and-demo-refresh-plan.zh-CN.md
index be36fe6..8b63526 100644
--- a/docs/markdown-and-demo-refresh-plan.zh-CN.md
+++ b/docs/markdown-and-demo-refresh-plan.zh-CN.md
@@ -28,8 +28,18 @@ Web 保留已有文字、引用和表格视觉风格。表格和代码块增加
## 完成情况
-已完成双端表格、代码块内部横向滚动与原始 Markdown 复制;移动端行内代码使用真实圆角容器,并调整正文、标题、列表、引用间距。Web 深浅主题、普通 HTTP 复制与原生 Android 滚动、复制已实测。
+已完成双端表格、代码块内部横向滚动与原始 Markdown 复制;移动端行内代码使用原生行内文本样式,并调整正文、标题、列表、引用间距。Web 深浅主题、普通 HTTP 复制与原生 Android 滚动、复制已实测。
已通过 42 项前端测试、移动端 TypeScript 检查、Go HTTP API 测试与 Android 原生构建。用户附件顺序已覆盖混合图片/文件的后端测试,双端显示回归测试确认助手块顺序不变。
已更新中英文共 10 份移动端 GIF 与 2 份 Web 生图 GIF。移动端保持原始真实会话和交付产物,Word/PPT 使用原有 WPS 展示;双语 README 均已在浏览器检查,五个案例按 3+2 居中展示,资源全部可加载。GIF 逐帧解码核对通过,未额外整体压暗。
+
+## 行内代码与相邻图片间距修正
+
+参照 Web 的行内 code 样式和 Taste Skill 的文字层级、克制配色原则,移动端使用平台等宽字体(iOS Menlo、Android monospace)、14pt 常规字重(正文 16pt)、深灰文字 `#3f414a` 和近白浅灰背景 `#f1f2f5`。沿用 Markdown 库原生嵌套 Text 的渲染,让代码参与正文基线、换行、选择与系统字号缩放;移除独立 View 容器、宽度上下文和文字测量。按用户最新确认,本次不要求圆角。
+
+仅清除整个 Markdown 文本块第一项的顶部 margin 和最后一项的底部 margin,避免段尾空白与会话块间距叠加,尤其是正文后紧跟 readimage / generateimage 的情况。文本内部的段落、标题、列表和引用间距保留;图片工具的 44pt 展开触控区不缩小。
+
+演示继续复用原始真实会话、图片和交付文件,重新录制最新版 Android 的完整会话页面;Word/PPT 保留原先 WPS 成品展示,中英文各五个案例及 3+2 排列不变。
+
+本次修正已通过移动端 TypeScript 检查与 Android 原生构建,并在模拟器中检查中英文、连续行内代码、长路径、引用、表格内代码及 130% 系统字号。已重录并替换中英文 10 份移动端 GIF 和中文 4 份关键帧截图;原始会话与交付文件摘要不变,逐帧导出校验通过,双语 README 的演示资源引用均可解析。Web 现有行内 code 与文本边界规则保持不变,当前演示无需因本次移动端修正而重新录制。
diff --git a/mobile/src/MarkdownText.tsx b/mobile/src/MarkdownText.tsx
index 7b74ee1..126935a 100644
--- a/mobile/src/MarkdownText.tsx
+++ b/mobile/src/MarkdownText.tsx
@@ -1,5 +1,5 @@
-import { createContext, memo, useContext, useEffect, useRef, useState } from 'react'
-import { Linking, Platform, Pressable, ScrollView, StyleSheet, Text, View, useWindowDimensions } from 'react-native'
+import { Children, cloneElement, isValidElement, memo, useEffect, useRef, useState } from 'react'
+import { Linking, Platform, Pressable, ScrollView, StyleSheet, Text, View, type StyleProp, type ViewStyle } from 'react-native'
import Markdown, { MarkdownIt, type ASTNode } from 'react-native-markdown-display'
import * as Clipboard from 'expo-clipboard'
import { Check, Copy } from 'lucide-react-native'
@@ -33,26 +33,9 @@ function CopyButton({ raw, kind }: { raw: string; kind: 'table' | 'code' }) {
}}>{status === 'copied' ? <Check size={14} color={muted} /> : <Copy size={14} color={muted} />}<Text accessibilityLiveRegion="polite" style={styles.action}>{t(label)}</Text></Pressable>
}
-const MarkdownWidth = createContext<number | undefined>(undefined)
-function InlineCode({ text, cellWidth }: { text: string; cellWidth?: number }) {
- const { width } = useWindowDimensions()
- const contentWidth = useContext(MarkdownWidth)
- const available = Math.max(48, cellWidth ?? contentWidth ?? width - 60)
- const [size, setSize] = useState({ width: available, height: 24 })
- // Android Text background spans do not clip to borderRadius. A measured inline
- // view gives both platforms the same rounded pill without estimating glyphs.
- return <View style={[styles.inline, { width: Math.min(available, size.width), height: size.height }]}>
- <Text selectable style={styles.inlineText} onTextLayout={({ nativeEvent: { lines } }) => {
- if (!lines.length) return
- const next = { width: lines.length > 1 ? available : Math.min(available, Math.ceil(lines[0].width) + 12), height: Math.ceil(lines.reduce((sum, line) => sum + line.height, 0)) + 4 }
- setSize(old => old.width === next.width && old.height === next.height ? old : next)
- }}>{text}</Text>
- </View>
-}
-
-function CodePanel({ node }: { node: SourceNode }) {
+function CodePanel({ node, style }: { node: SourceNode; style?: StyleProp<ViewStyle> }) {
const { t } = useLocale()
- return <View style={styles.panel}>
+ return <View style={[styles.panel, style]}>
<View style={styles.toolbar}><Text style={styles.caption}>{node.sourceInfo?.trim().split(/\s/)[0] || t('代码')}</Text><CopyButton raw={node.sourceMeta?.markdownSource ?? node.content} kind="code" /></View>
<ScrollView horizontal nestedScrollEnabled directionalLockEnabled showsHorizontalScrollIndicator accessibilityLabel={t('代码,可左右滚动')} contentContainerStyle={styles.codeContent}>
<Text selectable style={styles.code}>{node.content.replace(/\n$/, '')}</Text>
@@ -73,14 +56,15 @@ function columnWidths(table: ASTNode) {
export const MarkdownText = memo(function MarkdownText({ text }: { text: string }) {
const { t } = useLocale()
- const [width, setWidth] = useState<number>()
- return <View onLayout={({ nativeEvent: { layout } }) => setWidth(old => old === layout.width ? old : layout.width)}><MarkdownWidth.Provider value={width}><Markdown markdownit={parser} style={markdown} rules={{
- image: node => <Text key={node.key} selectable>{'![' + (node.attributes.alt ?? '') + '](' + node.attributes.src + ')'}</Text>,
- code_inline: (node, _children, parents) => {
- const table = parents.find(parent => parent.type === 'table')
- const cell = parents.find(parent => parent.type === 'td' || parent.type === 'th')
- return <InlineCode key={node.key} text={node.content} cellWidth={table && cell ? columnWidths(table)[cell.index] - 28 : undefined} />
+ return <Markdown markdownit={parser} style={markdown} rules={{
+ body: (node, children, _parents, nodeStyles) => {
+ const blocks = Children.toArray(children)
+ return <View key={node.key} style={nodeStyles._VIEW_SAFE_body}>{blocks.map((child, index) =>
+ isValidElement<{ style?: StyleProp<ViewStyle> }>(child) ? cloneElement(child, { style: [child.props.style,
+ index === 0 && styles.firstBlock, index === blocks.length - 1 && styles.lastBlock] }) : child,
+ )}</View>
},
+ image: node => <Text key={node.key} selectable>{'![' + (node.attributes.alt ?? '') + '](' + node.attributes.src + ')'}</Text>,
fence: node => <CodePanel key={node.key} node={node} />,
code_block: node => <CodePanel key={node.key} node={node} />,
table: (node: SourceNode, children) => <View key={node.key} style={[styles.panel, { backgroundColor: '#ffffff80' }]}>
@@ -97,14 +81,13 @@ export const MarkdownText = memo(function MarkdownText({ text }: { text: string
const table = parents.find(parent => parent.type === 'table')
return <View key={node.key} style={[styles.cell, { width: table ? columnWidths(table)[node.index] : 140 }]}>{children}</View>
},
- }} onLinkPress={url => { if (/^https?:\/\//i.test(url)) void Linking.openURL(url).catch(() => {}); return false }}>{text}</Markdown></MarkdownWidth.Provider></View>
+ }} onLinkPress={url => { if (/^https?:\/\//i.test(url)) void Linking.openURL(url).catch(() => {}); return false }}>{text}</Markdown>
})
const styles = StyleSheet.create({
panel: { alignSelf: 'stretch', minWidth: 0, marginTop: 8, marginBottom: 18, borderWidth: StyleSheet.hairlineWidth, borderColor: border, borderRadius: 10, backgroundColor: paper, overflow: 'hidden' },
toolbar: { minHeight: 44, flexDirection: 'row', alignItems: 'center', justifyContent: 'space-between', paddingLeft: 14, paddingRight: 6, borderBottomWidth: StyleSheet.hairlineWidth, borderBottomColor: border, backgroundColor: '#f4f5f8' },
- inline: { borderRadius: 5, backgroundColor: '#eef0f4', borderWidth: StyleSheet.hairlineWidth, borderColor: border, paddingHorizontal: 5, paddingVertical: 1, overflow: 'hidden' },
- inlineText: { fontFamily: mono, color: '#414756', fontSize: 13, lineHeight: 20 },
+ firstBlock: { marginTop: 0 }, lastBlock: { marginBottom: 0 },
caption: { fontSize: 11, fontWeight: '500', color: muted },
copy: { minHeight: 44, minWidth: 72, paddingHorizontal: 8, flexDirection: 'row', alignItems: 'center', justifyContent: 'center', gap: 6 },
action: { fontSize: 11, color: muted },
@@ -126,7 +109,7 @@ const markdown = StyleSheet.create({
bullet_list: { marginBottom: 12 }, ordered_list: { marginBottom: 12 },
list_item: { marginBottom: 6 },
link: { color: accent, textDecorationLine: 'underline' },
- code_inline: { fontFamily: mono, backgroundColor: '#eef0f4', color: '#414756', fontSize: 13, lineHeight: 20, borderWidth: 0, borderRadius: 4 },
+ code_inline: { fontFamily: mono, fontSize: 14, fontWeight: '400', color: '#3f414a', backgroundColor: '#f1f2f5', borderWidth: 0, padding: 0, borderRadius: 0 },
blockquote: { marginTop: 6, marginBottom: 18, paddingHorizontal: 15, paddingTop: 12, paddingBottom: 0, borderLeftWidth: 3, borderColor: '#d4d7e0', backgroundColor: '#f5f6f980' },
tr: { flexDirection: 'row', borderBottomWidth: StyleSheet.hairlineWidth, borderBottomColor: border },
thead: { backgroundColor: '#f4f5f8' },