From 0c2c906e3c9c94ef5ecb4d796763e05b77c7b95f Mon Sep 17 00:00:00 2001 From: JK Date: Mon, 9 Feb 2026 03:13:49 +0900 Subject: [PATCH] =?UTF-8?q?fix(reverse=5Fsync):=20verify=20=EC=8B=9C=20?= =?UTF-8?q?=EC=9D=B4=EB=AF=B8=EC=A7=80=20=EA=B2=BD=EB=A1=9C=20=EB=B6=88?= =?UTF-8?q?=EC=9D=BC=EC=B9=98=20=EB=B0=8F=20=EB=B6=88=ED=95=84=EC=9A=94?= =?UTF-8?q?=ED=95=9C=20=EC=9D=B4=EB=AF=B8=EC=A7=80=20=EB=B3=B5=EC=82=AC=20?= =?UTF-8?q?=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit _forward_convert()가 --attachment-dir로 /{page_id}/verify를 사용하여 roundtrip MDX의 이미지 경로가 원본과 달라지는 문제를 수정한다. pages.yaml에서 page path를 조회하여 올바른 attachment-dir를 전달하고, 검증 시 불필요한 이미지 복사를 --skip-image-copy 옵션으로 생략한다. Co-Authored-By: Claude Opus 4.6 --- confluence-mdx/bin/confluence_xhtml_to_markdown.py | 11 ++++++++--- confluence-mdx/bin/reverse_sync_cli.py | 13 ++++++++++++- 2 files changed, 20 insertions(+), 4 deletions(-) diff --git a/confluence-mdx/bin/confluence_xhtml_to_markdown.py b/confluence-mdx/bin/confluence_xhtml_to_markdown.py index 075196f94..4cb6277dc 100755 --- a/confluence-mdx/bin/confluence_xhtml_to_markdown.py +++ b/confluence-mdx/bin/confluence_xhtml_to_markdown.py @@ -2039,7 +2039,8 @@ def add_import(self, module_name, condition=True): else: self._imports[module_name] = False - def load_attachments(self, input_dir: str, output_dir: str, public_dir: str) -> None: + def load_attachments(self, input_dir: str, output_dir: str, public_dir: str, + skip_image_copy: bool = False) -> None: # Find all ac:image nodes first ac_image_nodes = self.soup.find_all('ac:image') attachments: List[Attachment] = [] @@ -2049,7 +2050,8 @@ def load_attachments(self, input_dir: str, output_dir: str, public_dir: str) -> for node in attachment_nodes: logging.debug(f"add attachment of {node}") attachment = Attachment(node, input_dir, output_dir, public_dir) - attachment.copy_to_destination() + if not skip_image_copy: + attachment.copy_to_destination() attachments.append(attachment) logging.debug(f"attachments: {attachments}") @@ -2154,6 +2156,8 @@ def main(): help='/public directory path') parser.add_argument('--attachment-dir', help='Directory to save attachments (default: output file directory)') + parser.add_argument('--skip-image-copy', action='store_true', + help='이미지 파일 복사를 생략 (경로만 지정대로 생성)') parser.add_argument('--log-level', choices=['debug', 'info', 'warning', 'error', 'critical'], default='info', @@ -2218,7 +2222,8 @@ def main(): GLOBAL_LINK_MAPPING = build_link_mapping(page_v1) converter = ConfluenceToMarkdown(html_content) - converter.load_attachments(input_dir, output_dir, args.public_dir) + converter.load_attachments(input_dir, output_dir, args.public_dir, + skip_image_copy=args.skip_image_copy) markdown_content = converter.as_markdown() with open(args.output_file, 'w', encoding='utf-8') as f: diff --git a/confluence-mdx/bin/reverse_sync_cli.py b/confluence-mdx/bin/reverse_sync_cli.py index 0170c637d..2c52bf02f 100644 --- a/confluence-mdx/bin/reverse_sync_cli.py +++ b/confluence-mdx/bin/reverse_sync_cli.py @@ -87,6 +87,15 @@ def _resolve_page_id(ko_mdx_path: str) -> str: raise ValueError(f"MDX path '{ko_mdx_path}' not found in var/pages.yaml") +def _resolve_attachment_dir(page_id: str) -> str: + """page_id에서 pages.yaml의 path를 조회하여 attachment-dir를 반환.""" + pages = yaml.safe_load(Path('var/pages.yaml').read_text()) + for page in pages: + if page['page_id'] == page_id: + return '/' + '/'.join(page['path']) + raise ValueError(f"page_id '{page_id}' not found in var/pages.yaml") + + def _forward_convert(patched_xhtml_path: str, output_mdx_path: str, page_id: str) -> str: """patched XHTML 파일을 forward converter로 MDX로 변환한다. @@ -99,11 +108,13 @@ def _forward_convert(patched_xhtml_path: str, output_mdx_path: str, page_id: str abs_input = Path(patched_xhtml_path).resolve() abs_output = Path(output_mdx_path).resolve() + attachment_dir = _resolve_attachment_dir(page_id) result = subprocess.run( [sys.executable, str(converter), '--log-level', 'warning', str(abs_input), str(abs_output), '--public-dir', str(var_dir.parent), - '--attachment-dir', f'/{page_id}/verify'], + '--attachment-dir', attachment_dir, + '--skip-image-copy'], capture_output=True, text=True, ) if result.returncode != 0: