Turn any technical book PDF into a Claude Code skill — ready to study, reference, and use while you work.
Python agent-skillsai-agentsbook-to-skillcontext-engineeringdocument-processingedtechknowledge-baseknowledge-managementllmpdf-to-markdownragself-studystudy-tools
fix(sanitize): strip deprecated and interlinear-annotation format controls (#182)
Shubham Srivastava9aecefe26797
diff --git a/book_to_skill/sanitize.py b/book_to_skill/sanitize.pyindex 2a2e4f5..08a2659 100644--- a/book_to_skill/sanitize.py+++ b/book_to_skill/sanitize.py@@ -57,10 +57,27 @@ _INVISIBLE_LETTER_CODEPOINTS = frozenset({0xFFA0, # HALFWIDTH HANGUL FILLER})+# 5. Deprecated / annotation format controls. All category Cf,+# Default_Ignorable, and render as nothing — the same invisible+# format-control shape as group 1, just blocks the original list missed.+# None has any use in extracted book prose.+_ANNOTATION_FORMAT_CODEPOINTS = frozenset({+ 0x206A, # INHIBIT SYMMETRIC SWAPPING+ 0x206B, # ACTIVATE SYMMETRIC SWAPPING+ 0x206C, # INHIBIT ARABIC FORM SHAPING+ 0x206D, # ACTIVATE ARABIC FORM SHAPING+ 0x206E, # NATIONAL DIGIT SHAPES+ 0x206F, # NOMINAL DIGIT SHAPES+ 0xFFF9, # INTERLINEAR ANNOTATION ANCHOR+ 0xFFFA, # INTERLINEAR ANNOTATION SEPARATOR+ 0xFFFB, # INTERLINEAR ANNOTATION TERMINATOR+})+_INVISIBLE_CODEPOINTS = (_ZERO_WIDTH_CODEPOINTS| _BIDI_CONTROL_CODEPOINTS| _INVISIBLE_LETTER_CODEPOINTS+ | _ANNOTATION_FORMAT_CODEPOINTS)# 4. The Unicode tag block. Originally language tags, now used to smuggle andiff --git a/tests/test_sanitize_annotation_controls.py b/tests/test_sanitize_annotation_controls.pynew file mode 100644index 0000000..97f013d--- /dev/null+++ b/tests/test_sanitize_annotation_controls.py@@ -0,0 +1,40 @@+"""Deprecated / interlinear-annotation format controls are stripped too.++These are category Cf, Default_Ignorable code points that render as nothing —+the same invisible format-control shape as the zero-width set — but the original+blocklist missed them, so they passed straight through the extraction scrub (and,+because the scanner shares is_invisible_codepoint, went unflagged there too).+"""++import sys+from pathlib import Path++ROOT_DIR = Path(__file__).resolve().parent.parent+sys.path.insert(0, str(ROOT_DIR))++from book_to_skill.sanitize import is_invisible_codepoint, sanitize_extracted_text++# U+206A-206F (deprecated format controls) + U+FFF9-FFFB (interlinear annotation).+ANNOTATION_CONTROLS = "".join(+ chr(cp) for cp in [*range(0x206A, 0x2070), 0xFFF9, 0xFFFA, 0xFFFB]+)+++def test_all_annotation_controls_are_invisible():+ assert all(is_invisible_codepoint(ord(c)) for c in ANNOTATION_CONTROLS)+++def test_annotation_controls_are_stripped_and_counted():+ text = f"study{ANNOTATION_CONTROLS}advice"+ cleaned, removed = sanitize_extracted_text(text)+ assert cleaned == "studyadvice"+ assert removed == len(ANNOTATION_CONTROLS)+++def test_visible_lookalikes_are_kept():+ # Braille blank (U+2800) and a musical symbol are real So characters, not+ # invisible format controls — they must survive.+ text = "a⠀b\U0001D159c"+ cleaned, removed = sanitize_extracted_text(text)+ assert cleaned == text+ assert removed == 0