The indent trigger was using .abs() which fired on both increased indent (non-indented → indented) AND decreased indent (indented → non-indented). This caused drop-cap style paragraphs (indented first line, flush-left continuation) to incorrectly split into two blocks. Per plan Phase 4.4 heuristic #2, indent change should only trigger when the current line is MORE indented (to the right, larger x0) than the block average - i.e., a new paragraph starting after non-indented text. It should NOT trigger for decreased indent (first line indented, rest flush-left). Fix: Remove .abs() and only check if line_x0 - block_avg_x0 > threshold. Tests: - test_indented_first_line_new_block: PASS (non-indented → indented splits) - test_indented_first_line_of_paragraph_not_split: PASS (drop cap stays together) - All 179 line module tests: PASS
71 lines
2.9 KiB
Python
Executable file
71 lines
2.9 KiB
Python
Executable file
#!/usr/bin/env python3
|
|
"""List public API items that need examples."""
|
|
|
|
import re
|
|
from pathlib import Path
|
|
|
|
# Items from lib.rs re-exports
|
|
LIB_EXPORTS = [
|
|
"PdfSource", "FileSource", "MmapSource", "HttpRangeSource", "RemoteOpts",
|
|
"ConfidenceSource", "map_confidence_source",
|
|
"Document", "PageExtraction", "PageIter", "PdfExtractor",
|
|
"extract_pdf", "extract_pdf_ndjson", "extract_pdf_streaming", "extract_text",
|
|
"ExtractionMetadata", "ExtractionResult", "PageResult",
|
|
"NamedEncoding", "Std14Metrics", "get_std14_metrics",
|
|
"combine", "walk_acroform_fields", "AcroFieldType", "AcroFormField", "ChoiceValue", "FormFieldValue",
|
|
"MarkdownOptions", "page_to_markdown", "page_to_markdown_with_links", "parse_anchors",
|
|
"block_to_markdown", "form_fields_to_markdown", "span_to_markdown", "Anchor",
|
|
"ExtractionOptions", "OutputOptions", "ReceiptsMode",
|
|
"PageClass", "PageClassification", "page_type_string",
|
|
"count_pages_tree", "LazyPageIter", "PageDict", "DEFAULT_MEDIABOX",
|
|
"AttachmentJson", "BeadJson", "BlockJson", "CellJson", "ExtractionQuality",
|
|
"RowJson", "SpanJson", "SpanRef", "TableJson", "ThreadJson",
|
|
"GridCandidate", "TableDetector", "TablePageContext",
|
|
"serialize_page_text", "TextOptions",
|
|
"TextState", "WordBoundaryDetector", "WordBoundaryManager",
|
|
"Glyph", "emit_glyph", "new_raw_glyph_list",
|
|
"Span", "merge_glyphs_to_spans", "CssHexColor",
|
|
]
|
|
|
|
def find_items_needing_examples():
|
|
"""Find items in the public API that lack examples."""
|
|
src_dir = Path('crates/pdftract-core/src')
|
|
items_without = []
|
|
|
|
for module_file in src_dir.glob('*.rs'):
|
|
with open(module_file, 'r') as f:
|
|
content = f.read()
|
|
lines = content.split('\n')
|
|
|
|
in_pub_struct = False
|
|
struct_name = None
|
|
doc_buffer = []
|
|
|
|
for i, line in enumerate(lines):
|
|
stripped = line.strip()
|
|
|
|
if stripped.startswith('pub struct '):
|
|
m = re.search(r'pub\s+struct\s+(\w+)', stripped)
|
|
if m:
|
|
struct_name = m.group(1)
|
|
in_pub_struct = True
|
|
doc_buffer = []
|
|
elif in_pub_struct and (stripped.startswith('pub ') or stripped == '}'):
|
|
# Check if struct has example
|
|
if struct_name in LIB_EXPORTS:
|
|
has_example = any('```rust' in d or '```no_run' in d for d in doc_buffer)
|
|
if not has_example:
|
|
items_without.append(('struct', struct_name, module_file.name))
|
|
in_pub_struct = False
|
|
doc_buffer = []
|
|
elif in_pub_struct:
|
|
doc_buffer.append(stripped)
|
|
|
|
return items_without
|
|
|
|
if __name__ == '__main__':
|
|
items = find_items_needing_examples()
|
|
print(f"Public API items without examples ({len(items)}):")
|
|
print()
|
|
for kind, name, file in sorted(items):
|
|
print(f" {kind:6} {name:30} ({file})")
|