Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 2 additions & 10 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -462,14 +462,6 @@ def flush_batch():
re.DOTALL | re.IGNORECASE
)

def _get_skip_ranges(content: str) -> List[Tuple[int, int]]:
return [(m.start(), m.end()) for m in SKIP_TAG_PATTERN.finditer(content)]

def _in_skip_range(pos: int, skip_ranges: List[Tuple[int, int]]) -> bool:
for start, end in skip_ranges:
if start <= pos < end:
return True
return False

def _decode_html_text(text: str) -> str:
decoded = html_module.unescape(text)
Expand Down Expand Up @@ -539,8 +531,8 @@ def process_html_file(input_path: str, output_path: Optional[str], resume: bool
with open(input_path, 'r', encoding='utf-8') as f:
content = f.read()

skip_ranges = _get_skip_ranges(content)
matches = [m for m in PARAGRAPH_PATTERN.finditer(content) if not _in_skip_range(m.start(), skip_ranges)]
content = SKIP_TAG_PATTERN.sub('', content)
matches = list(PARAGRAPH_PATTERN.finditer(content))
paragraph_count = len(matches)

checkpoint_path = get_checkpoint_path(output_path) if output_path else None
Expand Down
3 changes: 2 additions & 1 deletion test_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -421,7 +421,8 @@ def test_non_paragraph_content_preserved(self, tmp_path):
process_html_file(str(input_file), str(output_file))
result = output_file.read_text(encoding="utf-8")
assert "<h1>Title</h1>" in result
assert "<title>Test</title>" in result
assert "<head>" not in result
assert "<title>" not in result

def test_empty_paragraph_no_crash(self, tmp_path):
html = "<html><body><p></p><p>Real content here.</p></body></html>"
Expand Down