Commit 6d42447
committed
A/4: PR review comment 走 markdown 渲染 + diff webview 配色/移动端适配
范围与背景
----------
承接 A/3(PR review comment 内联到 diff 行),A/4 解决两件事:
1. **comment body 从"纯 escape+<br>"升级到真正的 markdown 渲染**:
fixture PR #938 上 Copilot 在 android/app/build.gradle L84 挂的
```suggestion 代码块之前被渲染成一坨转义后的纯文本,可读性差
2. **代码预览 webview 配色割裂 + 移动端不适配**:真机反馈——
`HtmlUtils.generateCodeHtml` 固定挂 highlight.js `default`(浅色主题)
但调用方传的是 `webDraculaBackgroundColorString`(深色底),
hljs 输出的深色 token 在深底上几乎不可见;且无 padding / 字号 /
line-height / overflow-x 处理,手机上排版不像原生 App
变更文件
--------
- **新增** lib/common/utils/comment_markdown.dart:包装 `markdown` 包的
`markdownToHtml`,开启 fenced-code / inline-code / autolinks;
XSS 底线:先自行前置 escape `<字母` / `</字母` / `<!` / `<?` 序列,
再喂给 markdown 走 `ExtensionSet.none` + `encodeHtml: true`。
失败降级到 5 字符 escape + `\n → <br>`
- **改** lib/common/utils/html_utils.dart:`generateCodeHtml` 按
`backgroundColor` 判定深/浅主题——深色挂 hljs `atom-one-dark` +
文字 `#e5e7eb`,浅色挂 `github` + 文字 `#24292f`;加 `-webkit-text-
size-adjust` / `padding:12px` / `font-family: ui-monospace, …` /
`font-size:14px` / `line-height:1.55` / `pre { overflow-x:auto; }`
等移动端排版
- **改** lib/page/issue/pull_request_files_page.dart:`_buildAddLineExtras`
的 body 从 `_htmlEscape+<br>` 换成 `renderCommentBodyToInlineHtml`;
author 仍走 `_htmlEscape`(纯 escape);dartdoc 从"A/3"改为"A/3 + A/4"
- **新增** test/utils/comment_markdown_test.dart:9 个测试,覆盖 null /
空串、fenced-code、inline-code、autolinks、XSS `<script>` / `<img
onerror>`、纯文本 fallback、多段落、fixture PR #938 完整 body
关键设计
--------
- **不改 pubspec.yaml**:`markdown` 是 `flutter_markdown_plus` 的传递
依赖(pubspec.lock 已锁),import 处显式 `// ignore:
depend_on_referenced_packages` 注明理由
- **XSS 根因排查**:`ExtensionSet.commonMark` 里的 `InlineHtmlSyntax`
**和** 标准 block 集里的 `HtmlBlockSyntax` 两处都放行 raw HTML;
即便扫掉 `InlineHtmlSyntax`,`HtmlBlockSyntax` 依然命中 `<script>`
这种块级标签起始。所以选源头 escape,而非只调 extension set
- **A/3 内联评论卡片**保留浅底黄+橙色左边框——在深底 diff 上刻意
"贴纸感"以便凸显评论,与主题解耦是有意的
验证
----
看代码:新增 2 文件 + 修改 2 文件(未动 A/3 的 test/html_utils_test.dart
及 A/3 卡片样式)
看编译:
- `fvm flutter test test/utils/` → 36 通过(含 A/4 新 9 个)
- `fvm flutter analyze lib/common/utils/{html_utils,comment_markdown}.dart
lib/page/issue/pull_request_files_page.dart
test/utils/comment_markdown_test.dart` → 0 issue
- GetDiagnostics 目标文件 → 空
看运行:**未重跑真机**——本次仅改
(a) markdown 转 HTML 字符串(纯 Dart,单测充分覆盖 XSS + 语义还原)
(b) 静态 CSS 字符串常量(highlight.js CDN 主题 + 字体 / padding /
overflow-x),无运行时分支逻辑,无 API 变更
已知缺口:
- 深/浅主题在真机 webview 上的**观感**未再拍图(fixture PR #938 上一轮
A/3 真机截图路径见前一次 commit 汇报);若后续需要视觉复核,走 adb
`screencap` 主路径即可
- hljs `atom-one-dark.min.css` CDN 可达性依赖 cdnjs(本仓库 A/2 起
即挂 cdnjs,无新增外部依赖风险)1 parent 2be57f5 commit 6d42447
4 files changed
Lines changed: 302 additions & 9 deletions
File tree
- lib
- common/utils
- page/issue
- test/utils
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
88 | 88 | | |
89 | 89 | | |
90 | 90 | | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
91 | 105 | | |
92 | 106 | | |
93 | 107 | | |
94 | 108 | | |
95 | | - | |
96 | | - | |
97 | | - | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
98 | 158 | | |
99 | 159 | | |
100 | 160 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
5 | 5 | | |
6 | 6 | | |
7 | 7 | | |
| 8 | + | |
8 | 9 | | |
9 | 10 | | |
10 | 11 | | |
| |||
177 | 178 | | |
178 | 179 | | |
179 | 180 | | |
180 | | - | |
| 181 | + | |
181 | 182 | | |
182 | 183 | | |
183 | 184 | | |
184 | 185 | | |
185 | 186 | | |
186 | 187 | | |
187 | | - | |
188 | | - | |
189 | | - | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
190 | 192 | | |
191 | 193 | | |
192 | 194 | | |
| |||
203 | 205 | | |
204 | 206 | | |
205 | 207 | | |
206 | | - | |
207 | | - | |
| 208 | + | |
| 209 | + | |
| 210 | + | |
208 | 211 | | |
209 | 212 | | |
210 | 213 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
0 commit comments