Skip to content

Commit 9b2bb66

Browse files
graycreateclaude
andcommitted
docs: add CSS-like stylesheet API and TDD requirements
Major updates to planning documents: 1. RichView API (richview_api.md): - Added comprehensive RenderStylesheet system with CSS-like styling - 8 element-specific style types: TextStyle, HeadingStyle, LinkStyle, CodeStyle, BlockquoteStyle, ListStyle, MentionStyle, ImageStyle - Built-in GitHub Markdown styling as default - Support for dark mode adaptive styles - Removed WebView degradation (no fallback) - Updated error handling: crash in DEBUG, catch in RELEASE - Added comprehensive SwiftUI Preview examples (8 preview variants) - Sample HTML for: basic, code, quotes, lists, complex content 2. Technical Plan (richtext_plan.md): - Removed all WebView degradation/fallback references - Added TDD requirements for each phase: * Phase 1: HTMLToMarkdownConverter & MarkdownRenderer unit tests * Phase 2: Complete coverage (85%+) with integration tests * Phase 3: Performance tests, cache tests, error handling tests - Added SwiftUI Preview requirements for each phase - Updated error handling strategy (DEBUG crash vs RELEASE catch) - Removed DegradationChecker, focus on full HTML support Key design changes: - Stylesheet system similar to CSS with element selectors - GitHub Markdown styling built-in (.default preset) - Customizable per-element: fonts, colors, spacing, borders - Code highlighting with 9 theme options - Support for heading levels (h1-h6) with individual overrides - Mention styling with background/padding options - Image max-width/max-height with content mode control Testing requirements: - Unit test coverage > 80% (Phase 1), > 85% (Phase 2) - SwiftUI Previews for all element types - Performance benchmarks (< 50ms render, 60fps scroll) - Error handling tests (DEBUG crash, RELEASE catch) 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
1 parent 1c8eac0 commit 9b2bb66

File tree

2 files changed

+775
-105
lines changed

2 files changed

+775
-105
lines changed

.plan/richtext_plan.md

Lines changed: 96 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -463,10 +463,31 @@ Models/ + Extensions/
463463
- [ ] 处理代码块 (无高亮)
464464
- [ ] 实现 `Components/RichTextView.swift` 基础 UITextView 包装
465465

466+
**TDD 测试要求**:
467+
- [ ] **HTMLToMarkdownConverter 单元测试**
468+
- [ ] 测试基础标签转换 (p, br, strong, em, a, code, pre)
469+
- [ ] 测试 V2EX URL 修正 (// → https://)
470+
- [ ] 测试文本转义 (特殊字符)
471+
- [ ] 测试空内容和 nil 处理
472+
- [ ] 测试不支持的标签 (DEBUG 模式应crash)
473+
- [ ] **MarkdownRenderer 单元测试**
474+
- [ ] 测试基础 Markdown → AttributedString
475+
- [ ] 测试加粗、斜体渲染
476+
- [ ] 测试链接渲染
477+
- [ ] 测试代码块渲染 (无高亮)
478+
- [ ] 测试空 Markdown 处理
479+
- [ ] **SwiftUI Preview**
480+
- [ ] 创建 RichView_Previews with 基础示例
481+
- [ ] 验证文本、加粗、斜体显示
482+
- [ ] 验证链接点击区域
483+
- [ ] Dark mode 预览
484+
466485
**验收标准**:
467-
- 能够正确转换简单的 V2EX HTML
468-
- 能够显示基础文本格式
469-
- 链接可点击
486+
- ✅ 能够正确转换简单的 V2EX HTML
487+
- ✅ 能够显示基础文本格式
488+
- ✅ 链接可点击
489+
- ✅ 单元测试覆盖率 > 80%
490+
- ✅ SwiftUI Preview 正常显示
470491

471492
### Phase 2: 完整功能 (3-4天)
472493

@@ -495,12 +516,48 @@ Models/ + Extensions/
495516
- [ ] 高度自适应
496517
- [ ] 实现 `Models/RichViewEvent.swift` 事件模型
497518
- [ ] 实现 `Models/RenderConfiguration.swift` 配置模型
519+
- [ ] 实现 `Models/RenderStylesheet.swift` 样式配置模型
520+
521+
**TDD 测试要求**:
522+
- [ ] **HTMLToMarkdownConverter 完整测试**
523+
- [ ] 测试图片标签转换 (img src 修正, alt属性)
524+
- [ ] 测试 @提及转换 (`<a href="/member/xxx">``[@xxx](@mention:xxx)`)
525+
- [ ] 测试列表转换 (ul, ol, li, 嵌套列表)
526+
- [ ] 测试blockquote转换
527+
- [ ] 测试标题转换 (h1-h6)
528+
- [ ] 测试图片链接包裹 (`<a><img></a>`)
529+
- [ ] 测试混合内容 (图片+文本+代码)
530+
- [ ] **V2EXMarkupVisitor 完整测试**
531+
- [ ] 测试图片 NSTextAttachment 创建
532+
- [ ] 测试列表缩进和符号
533+
- [ ] 测试引用样式应用
534+
- [ ] 测试代码高亮 (多种语言)
535+
- [ ] 测试 @mention 样式和属性
536+
- [ ] **AsyncImageAttachment 测试**
537+
- [ ] Mock Kingfisher 测试异步加载
538+
- [ ] 测试占位图显示
539+
- [ ] 测试加载失败处理
540+
- [ ] 测试图片尺寸限制
541+
- [ ] **RichTextView 交互测试**
542+
- [ ] 测试链接点击事件
543+
- [ ] 测试图片点击事件
544+
- [ ] 测试 @mention 点击事件
545+
- [ ] 测试文本选择
546+
- [ ] **SwiftUI Preview 完整示例**
547+
- [ ] 代码高亮 Preview (多种语言)
548+
- [ ] 图片加载 Preview
549+
- [ ] 列表和引用 Preview
550+
- [ ] @mention Preview
551+
- [ ] 复杂混合内容 Preview
552+
- [ ] 自定义样式 Preview
498553

499554
**验收标准**:
500-
- 所有 HTML 标签正确转换和显示
501-
- 代码高亮正常工作
502-
- 图片异步加载显示
503-
- 所有交互事件正常响应
555+
- ✅ 所有 HTML 标签正确转换和显示
556+
- ✅ 代码高亮正常工作 (测试至少 5 种语言)
557+
- ✅ 图片异步加载显示
558+
- ✅ 所有交互事件正常响应
559+
- ✅ 单元测试覆盖率 > 85%
560+
- ✅ SwiftUI Preview 涵盖所有元素类型
504561

505562
### Phase 3: 性能优化 (2-3天)
506563

@@ -512,11 +569,10 @@ Models/ + Extensions/
512569
- [ ] AttributedStringWrapper (NSObject 包装)
513570
- [ ] MD5 缓存 Key (通过 Extensions/String+Markdown.swift)
514571
- [ ] 缓存策略 (LRU)
515-
- [ ] 实现 `Support/DegradationChecker.swift`
516-
- [ ] HTML 大小检测 (>100KB 降级)
517-
- [ ] 黑名单标签检测
518-
- [ ] 转换错误检测
519-
- [ ] Analytics 埋点
572+
- [ ] 移除降级逻辑 (不需要 WebView fallback)
573+
- [ ] 所有标签必须支持
574+
- [ ] 不支持的标签在 DEBUG 下 crash
575+
- [ ] RELEASE 下 catch 错误并记录
520576
- [ ] 实现 `Support/PerformanceBenchmark.swift`
521577
- [ ] 渲染耗时测量
522578
- [ ] 内存占用监控
@@ -536,11 +592,35 @@ Models/ + Extensions/
536592
- [ ] 超长内容
537593
- [ ] 特殊字符
538594

595+
**TDD 测试要求**:
596+
- [ ] **RenderCache 单元测试**
597+
- [ ] 测试缓存存取 (set/get)
598+
- [ ] 测试 MD5 key 生成
599+
- [ ] 测试缓存淘汰 (LRU)
600+
- [ ] 测试线程安全 (并发读写)
601+
- [ ] 测试缓存统计 (hit rate)
602+
- [ ] **PerformanceBenchmark 测试**
603+
- [ ] 测试渲染时间测量准确性
604+
- [ ] 测试内存占用监控
605+
- [ ] 测试缓存命中率计算
606+
- [ ] **性能压力测试**
607+
- [ ] 100 个不同内容连续渲染 (测试缓存)
608+
- [ ] 超长内容渲染 (10KB+ HTML)
609+
- [ ] 复杂内容渲染 (图片+代码+列表混合)
610+
- [ ] 列表滚动性能 (100+ items, 60fps)
611+
- [ ] **错误处理测试**
612+
- [ ] DEBUG 模式: 不支持标签 crash 测试
613+
- [ ] RELEASE 模式: 错误 catch 测试
614+
- [ ] 空内容处理测试
615+
- [ ] 损坏 HTML 处理测试
616+
539617
**验收标准**:
540-
- 缓存命中率 > 80%
541-
- 渲染速度 < 50ms (单条回复)
542-
- 内存占用减少 70%+
543-
- 流畅滚动 (60fps)
618+
- ✅ 缓存命中率 > 80%
619+
- ✅ 渲染速度 < 50ms (单条回复)
620+
- ✅ 内存占用减少 70%+ (vs HtmlView)
621+
- ✅ 流畅滚动 (60fps, 100+ items)
622+
- ✅ 性能测试通过 (自动化)
623+
- ✅ 错误处理符合 DEBUG/RELEASE 策略
544624

545625
### Phase 4: 集成与测试 (2-3天)
546626

0 commit comments

Comments
 (0)