Skip to content

armgit / cindy

Public Imported from GitHub
0

Consider it done. The open-source AI agent that works out of the box · 想到,就能做到。开源、开箱即用的 AI Agent。

fix(mobile): 分享图与删除线链接保留外层强调

Dash484115b791b9
diff --git a/apps/mobile/src/__tests__/chatPathCandidate.test.ts b/apps/mobile/src/__tests__/chatPathCandidate.test.ts
index ac55e6e57b..f9c6761345 100644
--- a/apps/mobile/src/__tests__/chatPathCandidate.test.ts
+++ b/apps/mobile/src/__tests__/chatPathCandidate.test.ts
@@ -691,7 +691,7 @@ describe('路径 chip 的可点信号(源码级守卫)', () => {
expect(body, '未复用 label 形态判定').toContain('chatPathLabelReadsAsFileReference');
// 两个分支都在:套 chip 的与不套的。
expect(body, '缺少套等宽 chip 的分支').toMatch(/markdownInlineCode[\s\S]*markdownPathChip/);
- expect(body, '缺少不套等宽的分支').toMatch(/\[baseStyle, styles\.markdownPathChip\]/);
+ expect(body, '缺少不套等宽的分支').toMatch(/\[baseStyle, underlineDecoration\(styles, baseStyle, styles\.markdownPathChip\)\]/);
});
// ── 收敛检查点(PR #1144 两轮 review 各捉到一个「有下划线却点不动」) ──
@@ -705,7 +705,10 @@ describe('路径 chip 的可点信号(源码级守卫)', () => {
const helperEnd = src.indexOf('\n}', helperStart);
const helperBody = src.slice(helperStart, helperEnd);
// helper 自己必须按 onPress 决定下划线。
- expect(helperBody, 'helper 未按 onPress 分流').toMatch(/onPress \? styles\.markdownLink : undefined/);
+ // 下划线经 underlineDecoration 叠加(外层删除线时合并成两条线),仍只在有 onPress 时出现。
+ expect(helperBody, 'helper 未按 onPress 分流').toMatch(
+ /onPress \? underlineDecoration\(styles, base, styles\.markdownLink\) : undefined/,
+ );
// 除 helper 自身外,全文件不应再出现 styles.markdownLink 的**用法**。
// 注释行(含 helper 的 JSDoc,它会引用这个名字来说明规则)不算用法。
const lines = src.split('\n');
@@ -726,6 +729,26 @@ describe('路径 chip 的可点信号(源码级守卫)', () => {
).toEqual([]);
});
+ // `~~链接~~` / `~~src/a.ts~~`:RN textDecorationLine 是单值,直接叠 underline 会盖掉外层
+ // line-through。可点下划线一律经 underlineDecoration,遇到删除线合并成两条线。
+ it('可点下划线经 underlineDecoration 叠加,外层删除线时合并为 underline line-through', () => {
+ const src = readRenderer();
+ const merged = /markdownUnderlineStrike:\s*\{([^}]*)\}/.exec(src);
+ expect(merged, '未找到 markdownUnderlineStrike 样式定义').not.toBeNull();
+ expect(merged![1]).toMatch(/textDecorationLine:\s*'underline line-through'/);
+ const helperStart = src.indexOf('function underlineDecoration');
+ expect(helperStart, '未找到 underlineDecoration').toBeGreaterThan(-1);
+ const helperBody = src.slice(helperStart, src.indexOf('\n}', helperStart));
+ expect(helperBody).toMatch(/textDecorationLine === 'line-through'/);
+ expect(helperBody).toContain('styles.markdownUnderlineStrike');
+ // markdownPathChip 的每处用法都经 underlineDecoration(样式定义行除外)。
+ const direct = src
+ .split('\n')
+ .filter((line) => line.includes('styles.markdownPathChip'))
+ .filter((line) => !line.includes('underlineDecoration(styles, baseStyle, styles.markdownPathChip)'));
+ expect(direct, '有路径 chip 绕过 underlineDecoration 直接叠下划线').toEqual([]);
+ });
+
it('可点 inline 的 onPress 与样式取同一个值(不出现一边条件、一边无条件)', () => {
const src = readRenderer();
// 每个 clickableInlineStyle(styles, X, ...) 的 X 都必须同时是某处的 onPress={X}。
diff --git a/apps/mobile/src/__tests__/conversationShareRichSvg.test.ts b/apps/mobile/src/__tests__/conversationShareRichSvg.test.ts
index 84ef04585e..4ed2866759 100644
--- a/apps/mobile/src/__tests__/conversationShareRichSvg.test.ts
+++ b/apps/mobile/src/__tests__/conversationShareRichSvg.test.ts
@@ -56,6 +56,39 @@ describe("structured share fallback", () => {
expect(block.x + width).toBeLessThanOrEqual(cell.x + cell.width);
}
});
+ it("keeps outer emphasis on links and code wrapped by bold, italic or strikethrough", () => {
+ const layout = buildConversationShareSvgLayout({
+ allShareableIds: ["m"],
+ colors: {
+ background: "white",
+ surfaceElevated: "white",
+ border: "gray",
+ codeSurface: "gray",
+ inlineCode: "black",
+ surfaceChip: "gray",
+ textPrimary: "black",
+ textSecondary: "gray",
+ textTertiary: "gray",
+ syntax: {},
+ },
+ width: 640,
+ messages: [
+ {
+ clientId: "m",
+ kind: "assistant",
+ body: "**https://a.example/x** *https://b.example/y* ~~https://c.example/z~~ **`code`**",
+ },
+ ],
+ });
+ const find = (word: string) =>
+ layout.bubbles[0]!.textBlocks.find((t) => t.lines.join("") === word);
+ expect(find("https://a.example/x")).toMatchObject({ bold: true, decoration: "underline" });
+ expect(find("https://b.example/y")).toMatchObject({ italic: true, decoration: "underline" });
+ // SVG 只有一种装饰线:删除线优先于链接下划线。
+ expect(find("https://c.example/z")?.decoration).toBe("line-through");
+ expect(find("code")).toMatchObject({ bold: true, monospace: true });
+ });
+
it.each([lightColors, darkColors])(
"retains Markdown styles and table cells within the canvas",
(c) => {
diff --git a/apps/mobile/src/session/BotGroupMessageText.tsx b/apps/mobile/src/session/BotGroupMessageText.tsx
index dfa1f92af8..431903e0f2 100644
--- a/apps/mobile/src/session/BotGroupMessageText.tsx
+++ b/apps/mobile/src/session/BotGroupMessageText.tsx
@@ -16,11 +16,14 @@ type Styles = ReturnType<typeof makeStyles>;
function renderInlines(inlines: readonly MobileMarkdownInline[], styles: Styles): ReactNode[] {
return inlines.map((inline, index) => {
// 强调里的链接 / 代码等:外层套一层带强调样式的 Text,嵌套 Text 继承样式。
+ // 删除线里的链接:内层 underline 会盖掉外层 line-through(单值属性),改用合并值。
if (inline.marks?.length) {
const markStyles = { strong: styles.strong, emphasis: styles.emphasis, strikethrough: styles.strike };
return (
<Text key={index} style={inline.marks.map((mark) => markStyles[mark])}>
- {renderInlines([{ ...inline, marks: undefined }], styles)}
+ {inline.type === 'link' && inline.marks.includes('strikethrough')
+ ? <Text style={styles.linkStrike}>{inline.text}</Text>
+ : renderInlines([{ ...inline, marks: undefined }], styles)}
</Text>
);
}
@@ -97,6 +100,7 @@ const makeStyles = (colors: ThemeColors) => StyleSheet.create({
emphasis: { fontStyle: 'italic' },
strike: { textDecorationLine: 'line-through' },
link: { textDecorationLine: 'underline' },
+ linkStrike: { textDecorationLine: 'underline line-through' },
inlineCode: { fontFamily: monoFont, fontSize: typeScale.bodySmall, lineHeight: lineHeight.bodyLarge, backgroundColor: colors.surfaceChip },
quote: { borderLeftWidth: 2, borderLeftColor: colors.border, paddingLeft: spacing.md },
quoteText: { color: colors.textSecondary },
diff --git a/apps/mobile/src/session/MessageRenderer.tsx b/apps/mobile/src/session/MessageRenderer.tsx
index bef79c0f28..5bc30425cb 100644
--- a/apps/mobile/src/session/MessageRenderer.tsx
+++ b/apps/mobile/src/session/MessageRenderer.tsx
@@ -6122,7 +6122,21 @@ function clickableInlineStyle(
base: StyleProp<TextStyle>,
extra?: StyleProp<TextStyle>,
): StyleProp<TextStyle> {
- return [base, onPress ? styles.markdownLink : undefined, extra];
+ return [base, onPress ? underlineDecoration(styles, base, styles.markdownLink) : undefined, extra];
+}
+
+/**
+ * 可点下划线与外层删除线共存:RN 的 textDecorationLine 是单值,后叠的 underline 会盖掉
+ * `~~链接~~` 的 line-through。base 已带删除线时改用合并值,两条线都画。
+ */
+function underlineDecoration(
+ styles: ReturnType<typeof makeStyles>,
+ base: StyleProp<TextStyle>,
+ underline: StyleProp<TextStyle>,
+): StyleProp<TextStyle> {
+ return StyleSheet.flatten(base)?.textDecorationLine === 'line-through'
+ ? [underline, styles.markdownUnderlineStrike]
+ : underline;
}
function markdownMarkStyle(
@@ -6173,8 +6187,8 @@ function LinkPathChipSpan({
candidate={candidate}
chipStyle={
codeStyled
- ? [baseStyle, styles.markdownInlineCode, styles.markdownPathChip]
- : [baseStyle, styles.markdownPathChip]
+ ? [baseStyle, styles.markdownInlineCode, underlineDecoration(styles, baseStyle, styles.markdownPathChip)]
+ : [baseStyle, underlineDecoration(styles, baseStyle, styles.markdownPathChip)]
}
display={display}
// 未点亮一律回落正文样式(与桌面一致:未解析的 local-candidate 渲染成纯 span)。
@@ -6203,7 +6217,7 @@ function InlineCodePathSpan({
return (
<ChatPathChipSpan
candidate={candidate}
- chipStyle={[baseStyle, styles.markdownInlineCode, styles.markdownPathChip]}
+ chipStyle={[baseStyle, styles.markdownInlineCode, underlineDecoration(styles, baseStyle, styles.markdownPathChip)]}
display={text}
plainStyle={[baseStyle, styles.markdownInlineCode]}
SpanText={SpanText}
@@ -8972,6 +8986,7 @@ const makeStyles = (colors: ThemeColors) => StyleSheet.create({
// 与普通强调的区别只在语义,视觉上沿用 italic 已足够。
markdownMathInline: { fontStyle: 'italic' },
markdownStrike: { textDecorationLine: 'line-through' },
+ markdownUnderlineStrike: { textDecorationLine: 'underline line-through' },
// 行内 code:零底色 + 等宽字体 + 文字压暗(参照 Codex 客户端)。
// 不给底色是平台约束:RN 嵌套在 Text 内的 inline 片段只认 backgroundColor,不认
// borderRadius(同 sessionLinkChipText 的注释),底色在这里只能是直角方块,成段
diff --git a/apps/mobile/src/session/conversationShareRichSvg.ts b/apps/mobile/src/session/conversationShareRichSvg.ts
index ec805fa396..24d5acb407 100644
--- a/apps/mobile/src/session/conversationShareRichSvg.ts
+++ b/apps/mobile/src/session/conversationShareRichSvg.ts
@@ -2,6 +2,7 @@ import { latexToUnicodeApproximation } from "@cindy/maker-shared/math-markdown";
import { i18n } from "@/i18n";
import { tokenizeCode } from "@/session/codeHighlight";
import {
+ mobileMarkdownInlineHasMark,
parseMobileMarkdown,
type MobileMarkdownBlock,
type MobileMarkdownInline,
@@ -164,15 +165,15 @@ export function layoutConversationShareRichBody(
? latexToUnicodeApproximation(inline.text)
: inline.text,
color: inline.type === "code" ? colors.inlineCode : colors.textPrimary,
- bold: bold || inline.type === "strong",
- italic: inline.type === "emphasis",
+ bold: bold || mobileMarkdownInlineHasMark(inline, "strong"),
+ italic: mobileMarkdownInlineHasMark(inline, "emphasis"),
monospace: inline.type === "code",
- decoration:
- inline.type === "link"
+ // SVG 只能画一种装饰线;图片里的链接点不动,删除线(内容已作废)优先于链接下划线。
+ decoration: mobileMarkdownInlineHasMark(inline, "strikethrough")
+ ? "line-through"
+ : inline.type === "link"
? "underline"
- : inline.type === "strikethrough"
- ? "line-through"
- : undefined,
+ : undefined,
});
}
flush();
diff --git a/apps/mobile/src/session/conversationShareSvgLayout.ts b/apps/mobile/src/session/conversationShareSvgLayout.ts
index 25646a4164..e9ad513e2d 100644
--- a/apps/mobile/src/session/conversationShareSvgLayout.ts
+++ b/apps/mobile/src/session/conversationShareSvgLayout.ts
@@ -7,6 +7,7 @@ import {
type ShareSvgRect,
} from "@/session/conversationShareRichSvg";
import {
+ mobileMarkdownInlineHasMark,
parseMobileMarkdown,
type MobileMarkdownBlock,
type MobileMarkdownInline,
@@ -424,7 +425,7 @@ function markdownInlineParts(
inline.alt.trim() || i18n.t("message.renderer.imageFallbackTitle")
);
}
- if (inline.type === "strikethrough") {
+ if (mobileMarkdownInlineHasMark(inline, "strikethrough")) {
return `~~${inline.text}~~`;
}
return inline.text;
diff --git a/apps/mobile/src/session/messageMarkdown.ts b/apps/mobile/src/session/messageMarkdown.ts
index 754f710953..96fd404f97 100644
--- a/apps/mobile/src/session/messageMarkdown.ts
+++ b/apps/mobile/src/session/messageMarkdown.ts
@@ -1108,6 +1108,11 @@ function parseInlines(
return out.length > 0 ? out : [{ type: 'text', text: input }];
}
+/** 该 inline 是否呈现为某种强调:自身就是该类型,或被外层同类强调包裹(marks)。样式消费方统一用它判断。 */
+export function mobileMarkdownInlineHasMark(inline: MobileMarkdownInline, mark: MobileMarkdownInlineMark): boolean {
+ return inline.type === mark || inline.marks?.includes(mark) === true;
+}
+
function isMarkedInline(
inline: MobileMarkdownInline,
): inline is Extract<MobileMarkdownInline, { type: MobileMarkdownInlineMark }> {