Skip to content

Commit 665a5bd

Browse files
jk-kim0claude
andcommitted
fix(reverse_sync): roundtrip verifier 정규화를 추가합니다
- _normalize_empty_list_items: 빈 줄 치환 → 줄째 제거로 변경 - _normalize_consecutive_blank_lines: 연속 빈 줄(3+) → 단일 빈 줄 정규화 추가 - _normalize_blank_line_after_br: <br/> 뒤 빈 줄 제거 정규화 추가 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent f42f8ab commit 665a5bd

2 files changed

Lines changed: 36 additions & 10 deletions

File tree

confluence-mdx/bin/reverse_sync/roundtrip_verifier.py

Lines changed: 35 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -106,26 +106,50 @@ def _normalize_empty_bold(text: str) -> str:
106106

107107

108108
def _normalize_empty_list_items(text: str) -> str:
109-
"""내용 없는 번호 리스트 항목(예: `` 12.``)을 빈 줄로 치환한다.
109+
"""내용 없는 번호 리스트 항목(예: `` 12.``)을 줄째 제거한다.
110110
111111
Forward converter가 XHTML의 텍스트 없는 ``<li>`` (이미지만 포함)를
112112
번호만 있는 항목(``12.``)으로 변환한다. 이 항목은 시각적으로 무의미하므로
113113
improved.mdx에서 제거하더라도 XHTML 패치로 ``<li>`` 구조를 삭제할 수 없다.
114-
양쪽을 빈 줄로 정규화하여 이 차이를 무시한다.
114+
줄 전체(newline 포함)를 제거하여 이 차이를 무시한다.
115115
"""
116-
return re.sub(r'^([ \t]+)\d+\.\s*$', '', text, flags=re.MULTILINE)
116+
return re.sub(r'^[ \t]+\d+\.\s*\n', '', text, flags=re.MULTILINE)
117+
118+
119+
def _normalize_consecutive_blank_lines(text: str) -> str:
120+
"""연속 빈 줄(3개 이상의 개행)을 단일 빈 줄(2개 개행)로 정규화한다.
121+
122+
Forward converter가 블록 요소 사이에 추가 빈 줄을 삽입하거나,
123+
_normalize_empty_list_items가 줄을 제거한 뒤 남은 연속 빈 줄을
124+
정규화한다. MDX에서 빈 줄 수는 시각적으로 동일하다.
125+
"""
126+
return re.sub(r'\n{3,}', '\n\n', text)
127+
128+
129+
def _normalize_blank_line_after_br(text: str) -> str:
130+
"""<br/> 로 끝나는 줄 뒤의 빈 줄을 제거한다.
131+
132+
<br/> 자체가 줄바꿈을 생성하므로, 뒤따르는 빈 줄은 시각적으로
133+
무의미하다. improved.mdx에서 빈 리스트 번호(12.)를 제거한 뒤
134+
남은 빈 줄과 FC가 빈 줄 없이 출력하는 차이를 정규화한다.
135+
"""
136+
return re.sub(r'(<br\s*/>\n)\n+', r'\1', text)
117137

118138

119139
def _apply_minimal_normalizations(text: str) -> str:
120140
"""항상 적용하는 최소 정규화 (strict/lenient 모드 공통).
121141
122142
forward converter의 체계적 출력 특성에 의한 차이만 처리한다:
123-
- 인라인 이중 공백 → 단일 공백 (_normalize_consecutive_spaces_in_text)
124-
- <br/> 앞 공백 제거 (_normalize_br_space)
125-
- 링크 텍스트 앞뒤 공백 제거 (_normalize_link_text_spacing)
126-
- 빈 bold 마커(****) 정규화 (_normalize_empty_bold)
127-
- 내용 없는 번호 리스트 항목 제거 (_normalize_empty_list_items)
128-
- 문장 경계 줄바꿈 결합 (_normalize_sentence_breaks)
143+
- 인라인 이중 공백 → 단일 공백
144+
- <br/> 앞 공백 제거
145+
- 링크 텍스트 앞뒤 공백 제거
146+
- 빈 bold 마커(****) 정규화
147+
- 내용 없는 번호 리스트 항목 제거
148+
- 연속 빈 줄 정규화
149+
- 테이블 셀 패딩 정규화
150+
- 문장 경계 줄바꿈 결합
151+
- 첫 번째 h1 heading 제거
152+
- trailing 빈 줄 정규화
129153
130154
lenient 모드에서는 이 정규화 이후 _apply_normalizations가 추가로 적용된다.
131155
"""
@@ -134,6 +158,8 @@ def _apply_minimal_normalizations(text: str) -> str:
134158
text = _normalize_link_text_spacing(text)
135159
text = _normalize_empty_bold(text)
136160
text = _normalize_empty_list_items(text)
161+
text = _normalize_consecutive_blank_lines(text)
162+
text = _normalize_blank_line_after_br(text)
137163
text = _normalize_table_cell_padding(text)
138164
text = _normalize_sentence_breaks(text)
139165
text = _strip_first_heading(text)

confluence-mdx/tests/test_reverse_sync_roundtrip_verifier.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,7 @@ def test_minimal_norm_double_space_passes():
238238

239239

240240
def test_minimal_norm_br_space_passes():
241-
"""<br/> 앞 공백 차이는 strict 모드에서도 정규화된다."""
241+
"""<br/> 앞 공백 차이는 최소 정규화로 통과한다."""
242242
result = verify_roundtrip(
243243
expected_mdx="item <br/>next\n",
244244
actual_mdx="item<br/>next\n",

0 commit comments

Comments
 (0)