@@ -639,6 +639,42 @@ def test_gap_fully_deleted(self):
639639 result = patch_xhtml (xhtml , patches )
640640 assert 'IDENTIFIER</strong>조사' in result
641641
642+ def test_gap_is_node_leading_reduces_not_strips (self ):
643+ """gap 전체가 노드의 leading whitespace일 때, gap 축소 시 leading을 조정한다.
644+
645+ 재현 시나리오 (PR #979, page 883654669):
646+ XHTML: <code>{{..}}</code><span> 안의 값은...</span>
647+ old_plain_text: "...진행합니다. {{..}} 안의 값은..."
648+ new_plain_text: "...이동합니다. {{..}} 안의 값은..."
649+ 현상: gap " "→" " 축소 시 <span>의 leading " "가 전부 제거되어
650+ <span>안의 값은</span>이 됨 (올바른 결과: <span> 안의 값은</span>)
651+ 원인: gap_old(2) == leading(2)인 경우에도 leading=''로 전부 제거
652+ """
653+ xhtml = (
654+ '<p>'
655+ '미리 채워져 있는 내용들을 삭제하고 아래의 App Manifest를 진행합니다.'
656+ '<br/>'
657+ '<span style="background-color: rgb(254,222,200);"> </span>'
658+ '<code>{{..}}</code>'
659+ '<span style="background-color: rgb(254,222,200);"> 안의 값은 원하는 값으로 변경해 주세요.</span>'
660+ '</p>'
661+ )
662+ patches = [{
663+ 'xhtml_xpath' : 'p[1]' ,
664+ # collapse_ws로 " 안의" → " 안의"가 된 후 _apply_mdx_diff_to_xhtml 결과
665+ 'old_plain_text' : '미리 채워져 있는 내용들을 삭제하고 아래의 App Manifest를 진행합니다. {{..}} 안의 값은 원하는 값으로 변경해 주세요.' ,
666+ 'new_plain_text' : '미리 채워져 있는 내용을 삭제하고 아래 App Manifest를 이동합니다. {{..}} 안의 값은 원하는 값으로 변경해 주세요.' ,
667+ }]
668+ result = patch_xhtml (xhtml , patches )
669+ # gap " "→" " 축소 시, gap 전체가 노드 leading이므로 leading=" "으로 조정
670+ assert '> 안의 값은' in result , (
671+ f"leading should be reduced to 1 space, not stripped entirely: { result } "
672+ )
673+ # 버그 동작: leading이 전부 제거되어 ">안의"가 되면 안 됨
674+ assert '>안의 값은' not in result , (
675+ f"leading whitespace must not be stripped entirely: { result } "
676+ )
677+
642678 def test_gap_not_reduced_preserves_leading (self ):
643679 """gap이 축소되지 않으면 leading whitespace를 보존한다."""
644680 xhtml = (
0 commit comments