feat(word): add comment range highlighting with hover tooltip in HTML preview#77
Conversation
… preview - Track CommentRangeStart/End to open/close highlight spans - New GetCommentDisplayHtml renders comment author, date, initials as tooltip - CSS hover rule shows tooltip overlay on highlighted text Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
|
感谢贡献!这个 feature 方向对,实现也基本到位。合并前有两点需要补一下: 1. 请补一张截图(CONTRIBUTING Rule 2) 这是纯视觉 feature,按 CONTRIBUTING.md Rule 2 要求,feature PR 至少需要一张截图展示效果。请在 HTML 预览中悬停到高亮文字上,截一张 tooltip 显示的图贴到 PR description 里。 2. 跨段落批注会破坏 HTML `CommentRangeStart/End` 在 OOXML 中允许跨段落(例如批注从第 1 段的某个词开始,到第 3 段的某个词结束)。当前实现的 `commentDepth` 是 `RenderParagraphContentHtml` 方法内的局部变量,跨段落时:
修复思路:把 `commentDepth` 提升为 renderer 级字段(成员变量),并在段落渲染结束时,如果 `commentDepth > 0`,补一个 ``;下一个段落开始渲染时,如果 `commentDepth > 0`,先补一个 `<span class="comment-highlight">`(不带 tooltip,因为 tooltip 只在 start 段落出现一次即可)。 复现用例:在 Word 中选中一段横跨两个段落的文本,右键加批注,保存后用 `officecli watch` 查看 HTML,会看到 DOM 断裂。 其余的性能优化(Dictionary 缓存)、CSS 分层、测试等,按 CONTRIBUTING 约定是合并后由 maintainer 清理的,你不用处理。补完上面两点我就合。 |
|
@goworm 你举了一个跨 paragraph 批注的例子,我正好有需求要 跨 paragraph 或者 跨 run 进行批注,但是没找到 cli 怎么用才能实现呢。看代码好像不支持啊 |
|
另外批注的 commentReference 是包裹在一个 run 里面的, get 一个段落时,这个 run 是忽略的,但是给这个段落在批注后插入新 run,返回的 run id 没有跳过 commentReference 所在 run 唉,总之,给docx 打批注真是很复杂 |
Summary
Verification
构建
dotnet build src/officecli/officecli.csproj --no-restore
生成含批注的 Word 文档并预览 HTML
officecli blank test.docx
在 Word 中添加一条批注后保存,再用以下命令预览
officecli watch test.docx
鼠标悬停在黄色高亮文字上可看到 tooltip