Skip to content

Turn any technical book PDF into a Claude Code skill — ready to study, reference, and use while you work.

feat(extractor): detect Greek (Κεφάλαιο) chapter headings (#206)

Shubham Srivastava7e0795351f5f
diff --git a/book_to_skill/utils.py b/book_to_skill/utils.py
index ef8c914..0338292 100644
--- a/book_to_skill/utils.py
+++ b/book_to_skill/utils.py
@@ -207,6 +207,15 @@ _BN_CHAPTER = re.compile(
# inflected form ("В этой главе…", "Главная страница") from matching.
_RU_CHAPTER = re.compile(r"^\s*(?:#{1,6}\s+)?глава\s+([0-9]+)\b", re.IGNORECASE)
+# Greek chapter headings: "Κεφάλαιο 1", "ΚΕΦΑΛΑΙΟ 12", "## Κεφάλαιο 2".
+# "Κεφάλαιο" ("chapter") + a number. Greek uses ordinary Arabic digits, so — like
+# the Russian block above — no digit remap is needed. The 4th letter is written
+# [άα] because all-caps Greek drops the accent ("ΚΕΦΑΛΑΙΟ" has plain Α, not Ά),
+# and case-folding alone would not bridge Ά↔Α. Requiring whitespace then a number
+# keeps prose that merely uses the word (also "capital", "Το κεφάλαιο αυτό…") from
+# matching.
+_EL_CHAPTER = re.compile(r"^\s*(?:#{1,6}\s+)?κεφ[άα]λαιο\s+([0-9]+)\b", re.IGNORECASE)
+
# Korean chapter headings: "제1장 총칙", "## 제4장 근로시간과 휴식", "제6장의2 …".
# 제 + Arabic numeral + a classifier (장 chapter / 편 part / 절 section / 관
# subsection), with an optional "의N" branch suffix that Korean statutes use for
@@ -575,6 +584,9 @@ def _match_chapter_number(line: str) -> int | None:
rum = _RU_CHAPTER.match(s)
if rum:
return int(rum.group(1))
+ elm = _EL_CHAPTER.match(s)
+ if elm:
+ return int(elm.group(1))
km = _KO_CHAPTER.match(s)
if km:
@@ -596,6 +608,7 @@ def _chapter_number(line: str) -> int | None:
"## บทที่ ๑"), Hindi ("अध्याय 1", "अध्याय १", "## अध्याय 2"),
Bengali ("অধ্যায় 1", "অধ্যায় ১", "## অধ্যায় 2"),
Russian ("Глава 1", "ГЛАВА 12", "## Глава 2"),
+ Greek ("Κεφάλαιο 1", "ΚΕΦΑΛΑΙΟ 12", "## Κεφάλαιο 2"),
Korean ("제1장 총칙", "## 제4장 근로시간과 휴식"), and
Persian ("فصل ۱", "فصل اول", "فصل بیست و یکم", "بخش ۲: مفاهیم",
"## فصل ۱: مقدمه", PDF-glued "فصل سی و چهارمخداحافظ…") heading styles — each
diff --git a/tests/test_book_to_skill.py b/tests/test_book_to_skill.py
index b910441..42a3a0b 100644
--- a/tests/test_book_to_skill.py
+++ b/tests/test_book_to_skill.py
@@ -689,6 +689,26 @@ class TestDetectStructure:
assert _chapter_number("Главная страница") is None
assert _chapter_number("Глава") is None
+ def test_detects_greek_chapters(self):
+ """Greek headings: `Κεφάλαιο N`, incl. all-caps (accent-dropped) ΚΕΦΑΛΑΙΟ."""
+ text = (
+ "Κεφάλαιο 1 Εισαγωγή\nπεριεχόμενο\n"
+ "ΚΕΦΑΛΑΙΟ 2 Μέθοδοι\nπεριεχόμενο\n"
+ "Κεφάλαιο 3 Αποτελέσματα\nπεριεχόμενο"
+ )
+ assert detect_structure(text)["chapters_detected"] == 3
+
+ def test_greek_markdown_prefix(self):
+ text = "## Κεφάλαιο 1 Πρώτο\nπεριεχόμενο\n## Κεφάλαιο 2 Δεύτερο\nπεριεχόμενο"
+ assert detect_structure(text)["chapters_detected"] == 2
+
+ def test_greek_prose_is_not_a_chapter_heading(self):
+ """`κεφάλαιο` used in prose (no number, or mid-sentence) is not a heading."""
+ from book_to_skill.utils import _chapter_number
+
+ assert _chapter_number("Σε αυτό το κεφάλαιο θα δούμε") is None
+ assert _chapter_number("Κεφάλαιο") is None
+
# ── Korean chapter headings ────────────────────────────────────────────
def test_korean_je_n_jang(self):