diff --git a/sync.py b/sync.py index 319ade6..1f1d344 100644 --- a/sync.py +++ b/sync.py @@ -488,6 +488,10 @@ def create_diff_html(title, en_diff, en_old_lines, en_new_lines, cn_content=None return ''.join(result) + # 收集变更块信息用于导航 + change_blocks = [] + change_block_id = 0 + # 生成HTML html = f''' @@ -823,6 +827,166 @@ def create_diff_html(title, en_diff, en_old_lines, en_new_lines, cn_content=None .line-wrapper.blank-placeholder:hover .main-line {{ background-color: rgba(0, 123, 255, 0.02); }} + + /* 变更块高亮样式 */ + .line-wrapper.change-block {{ + border-left: 3px solid #007bff; + }} + + /* 导航浮窗样式 */ + .navigation-float {{ + position: fixed; + left: 20px; + top: 50%; + transform: translateY(-50%); + width: 280px; + max-height: 70vh; + background-color: #fff; + border: 1px solid #dee2e6; + border-radius: 8px; + box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15); + z-index: 1000; + overflow: hidden; + }} + + .navigation-header {{ + background-color: #007bff; + color: white; + padding: 12px 16px; + font-weight: bold; + font-size: 14px; + display: flex; + justify-content: space-between; + align-items: center; + }} + + .navigation-toggle {{ + background: none; + border: none; + color: white; + cursor: pointer; + font-size: 16px; + padding: 4px 8px; + border-radius: 4px; + transition: background-color 0.2s; + }} + + .navigation-toggle:hover {{ + background-color: rgba(255, 255, 255, 0.2); + }} + + .navigation-content {{ + max-height: calc(70vh - 50px); + overflow-y: auto; + padding: 8px; + }} + + .navigation-item {{ + padding: 10px 12px; + margin-bottom: 6px; + background-color: #f8f9fa; + border-radius: 4px; + cursor: pointer; + transition: all 0.2s; + border-left: 3px solid transparent; + }} + + .navigation-item:hover {{ + background-color: #e9ecef; + border-left-color: #007bff; + }} + + .navigation-item.active {{ + background-color: #e3f2fd; + border-left-color: #007bff; + }} + + .navigation-item-header {{ + display: flex; + justify-content: space-between; + align-items: center; + margin-bottom: 4px; + }} + + .navigation-item-number {{ + background-color: #007bff; + color: white; + font-size: 11px; + padding: 2px 6px; + border-radius: 10px; + font-weight: bold; + }} + + .navigation-item-type {{ + font-size: 11px; + padding: 2px 6px; + border-radius: 3px; + font-weight: bold; + text-transform: uppercase; + }} + + .navigation-item-type.added {{ + background-color: #28a745; + color: white; + }} + + .navigation-item-type.replaced {{ + background-color: #ffc107; + color: #212529; + }} + + .navigation-item-type.removed {{ + background-color: #dc3545; + color: white; + }} + + .navigation-item-preview {{ + font-size: 12px; + color: #6c757d; + font-family: 'Monaco', 'Menlo', 'Ubuntu Mono', monospace; + line-height: 1.3; + word-break: break-word; + }} + + .navigation-item-line {{ + font-size: 10px; + color: #adb5bd; + margin-top: 2px; + }} + + /* 导航浮窗收起状态 */ + .navigation-float.collapsed .navigation-content {{ + display: none; + }} + + .navigation-float.collapsed {{ + width: auto; + min-width: 160px; + }} + + /* 响应式设计 */ + @media (max-width: 768px) {{ + .navigation-float {{ + left: 10px; + width: 240px; + }} + + .navigation-float.collapsed {{ + min-width: 120px; + }} + }} + + @media (max-width: 480px) {{ + .navigation-float {{ + position: relative; + left: auto; + top: auto; + transform: none; + width: 100%; + max-height: none; + margin-bottom: 20px; + }} + }} @@ -834,6 +998,16 @@ def create_diff_html(title, en_diff, en_old_lines, en_new_lines, cn_content=None + +
中文翻译(含英文变更批注)
@@ -845,8 +1019,20 @@ def create_diff_html(title, en_diff, en_old_lines, en_new_lines, cn_content=None # 检查是否需要在此行之前插入空白行 if i in blank_lines_to_insert: additions_list = blank_lines_to_insert[i] - for addition_content in additions_list: - html += f'
' + change_block_id += 1 + + # 添加变更块到导航列表 + preview_text = additions_list[0][:50] + "..." if len(additions_list[0]) > 50 else additions_list[0] + change_blocks.append({ + 'id': change_block_id, + 'line': i, + 'type': '新增', + 'preview': preview_text, + 'count': len(additions_list) + }) + + for idx, addition_content in enumerate(additions_list): + html += f'
' html += '
' html += ' ' # 不显示行号 html += f'(新增英文内容占位)' @@ -870,7 +1056,21 @@ def create_diff_html(title, en_diff, en_old_lines, en_new_lines, cn_content=None # 判断是否为空行 is_empty = not line.strip() - html += f'
' + # 如果有变更(除了新增),添加到导航列表 + if has_changes and any(change['type'] in ['replaced', 'removed'] for change in changes): + change_block_id += 1 + preview_text = line[:50] + "..." if len(line) > 50 else line + change_type = "替换" if any(change['type'] == 'replaced' for change in changes) else "删除" + + change_blocks.append({ + 'id': change_block_id, + 'line': i, + 'type': change_type, + 'preview': preview_text, + 'count': 1 + }) + + html += f'
' html += f'
' html += f'{i}' html += f'{escaped_line if not is_empty else "(空行)"}' @@ -903,23 +1103,321 @@ def create_diff_html(title, en_diff, en_old_lines, en_new_lines, cn_content=None else: html += '
未找到对应的中文翻译页面
' + # 调试日志:打印change_blocks信息 + print(f"DEBUG: Final change_blocks length = {len(change_blocks)}") + for i, block in enumerate(change_blocks): + print(f"DEBUG: Final block {i}: {block}") + html += '''
'''