Add optional margin line number removal for PDF layout#594
Conversation
There was a problem hiding this comment.
2 issues found across 6 files
Prompt for AI agents (unresolved issues)
Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.
<file name="babeldoc/format/pdf/document_il/midend/paragraph_finder.py">
<violation number="1" location="babeldoc/format/pdf/document_il/midend/paragraph_finder.py:301">
P1: Margin line number removal config flag unconditionally disables the alternating line number merge fallback, even when no margin columns were actually detected. The `merge_alternating_line_number_paragraphs` guard uses `not remove_margin_line_numbers` (the config flag) rather than whether removal succeeded. When `remove_margin_line_numbers=True` but `_find_margin_line_number_columns` returns no columns, `remove_margin_line_numbers()` returns early without modifying anything, yet the merge fallback is still skipped. Documents with interleaved line numbers that don't form clear margin columns will keep fragmented body paragraphs.</violation>
</file>
<file name="babeldoc/format/pdf/document_il/midend/typesetting.py">
<violation number="1" location="babeldoc/format/pdf/document_il/midend/typesetting.py:1527">
P1: Vertical column advance uses modal width without a maximum safety bound, which can cause inter-column overlap for mixed-width content.</violation>
</file>
Reply with feedback, questions, or to request a fix.
Re-trigger cubic
|
|
||
| # 新增后处理:合并带行号交替的正文段落(a 正文、b 行号、c 正文 -> 合并 a 与 c,保留 b) | ||
| if getattr(self.translation_config, "merge_alternating_line_numbers", True): | ||
| if ( |
There was a problem hiding this comment.
P1: Margin line number removal config flag unconditionally disables the alternating line number merge fallback, even when no margin columns were actually detected. The merge_alternating_line_number_paragraphs guard uses not remove_margin_line_numbers (the config flag) rather than whether removal succeeded. When remove_margin_line_numbers=True but _find_margin_line_number_columns returns no columns, remove_margin_line_numbers() returns early without modifying anything, yet the merge fallback is still skipped. Documents with interleaved line numbers that don't form clear margin columns will keep fragmented body paragraphs.
Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At babeldoc/format/pdf/document_il/midend/paragraph_finder.py, line 301:
<comment>Margin line number removal config flag unconditionally disables the alternating line number merge fallback, even when no margin columns were actually detected. The `merge_alternating_line_number_paragraphs` guard uses `not remove_margin_line_numbers` (the config flag) rather than whether removal succeeded. When `remove_margin_line_numbers=True` but `_find_margin_line_number_columns` returns no columns, `remove_margin_line_numbers()` returns early without modifying anything, yet the merge fallback is still skipped. Documents with interleaved line numbers that don't form clear margin columns will keep fragmented body paragraphs.</comment>
<file context>
@@ -286,8 +289,19 @@ def process_page(self, page: Page):
+
# 新增后处理:合并带行号交替的正文段落(a 正文、b 行号、c 正文 -> 合并 a 与 c,保留 b)
- if getattr(self.translation_config, "merge_alternating_line_numbers", True):
+ if (
+ getattr(self.translation_config, "merge_alternating_line_numbers", True)
+ and not remove_margin_line_numbers
</file context>
| if not current_line_widths: | ||
| return [], False | ||
| current_y = box.y | ||
| current_x -= max( |
There was a problem hiding this comment.
P1: Vertical column advance uses modal width without a maximum safety bound, which can cause inter-column overlap for mixed-width content.
Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At babeldoc/format/pdf/document_il/midend/typesetting.py, line 1527:
<comment>Vertical column advance uses modal width without a maximum safety bound, which can cause inter-column overlap for mixed-width content.</comment>
<file context>
@@ -1455,6 +1490,60 @@ def _layout_typesetting_units(
+ if not current_line_widths:
+ return [], False
+ current_y = box.y
+ current_x -= max(
+ statistics.mode(current_line_widths) * line_skip,
+ line_width,
</file context>
Summary
remove_margin_line_numberstranslation option exposed through the CLI/config pathTesting
--remove-margin-line-numbers; debug tracking no longer includes the margin line numbersSummary by cubic
Add an optional flow to remove margin line numbers in PDFs to improve paragraph tracking and translation layout. Also skips reference sections and adds vertical text support in the local translator pipeline.
New Features
--remove-margin-line-numbers(config:remove_margin_line_numbers) to strip margin-only line number columns before paragraph tracking; auto-disables alternating line-number merge when on.llm_onlytranslators.verticalflag with updated boxes and layout.Bug Fixes
xobj_idwhen present (more accurateverticalandxobj_id).Written for commit 731ed6d. Summary will update on new commits.