AI turns documents or topics into real, native PowerPoint decks—with native shapes, transitions and animations, data-backed charts and tables on demand, audio narration from speaker notes, and support for your own .pptx templates. · by Hugo He
fix(pdf_to_md): keep numeric and labelled paragraphs between same-header tables
Claude4eb7b3d61f66
diff --git a/skills/ppt-master/scripts/source_to_md/pdf_to_md.py b/skills/ppt-master/scripts/source_to_md/pdf_to_md.pyindex 666fbb36..ecb6dd77 100644--- a/skills/ppt-master/scripts/source_to_md/pdf_to_md.py+++ b/skills/ppt-master/scripts/source_to_md/pdf_to_md.py@@ -478,6 +478,9 @@ NUMBER_RE = re.compile(r'[-+]?\d+(?:\.\d+)?')MODEL_COLUMN_RE = re.compile(r'^[((]\d+[))]$')TABLE_NOTE_PREFIX = '\u6ce8'TABLE_CONTINUATION_Y_RATIO = 0.88+# A printed page number left between split table parts; trusted only next to a+# ``<!-- Page N -->`` marker, never on its own.+PRINTED_PAGE_NUMBER_RE = re.compile(r'\d{1,4}')TABLE_SCAN_BOTTOM_RATIO = 0.92@@ -914,14 +917,6 @@ def _looks_like_outcome_row(row: list[str]) -> bool:return len(short_values) == len(values)-def _regression_group_labels(row: list[str], data_cols: int) -> list[str]:- """Infer repeated group labels for common regression-table headings."""- compact = "".join(row)- if "总样本" in compact and "国有" in compact and "非国有" in compact and data_cols == 7:- return ["总样本"] * 3 + ["国有企业"] * 2 + ["非国有企业"] * 2- return [""] * data_cols--def _flatten_regression_header(rows: list[list[str]]) -> list[list[str]]:"""Flatten multi-line regression headings into one Markdown header row."""if len(rows) < 3:@@ -942,10 +937,8 @@ def _flatten_regression_header(rows: list[list[str]]) -> list[list[str]]:return [header] + rows[2:]header_offset = 0- groups = [""] * (len(rows[0]) - 1)if not _looks_like_model_row(rows[0]) and _looks_like_model_row(rows[1]):header_offset = 1- groups = _regression_group_labels(rows[0], len(rows[1]) - 1)if not _looks_like_model_row(rows[header_offset]):return rows@@ -957,8 +950,6 @@ def _flatten_regression_header(rows: list[list[str]]) -> list[list[str]]:header = ["变量"]for idx, model in enumerate(model_row[1:]):pieces = []- if idx < len(groups) and groups[idx]:- pieces.append(groups[idx])if model:pieces.append(model)if idx + 1 < len(outcome_row) and outcome_row[idx + 1]:@@ -1439,24 +1430,24 @@ def _compatible_table_headers(first: list[str], second: list[str]) -> bool:return first[0] == second[0] and _markdown_col_count(first[0]) > 2-def _is_table_continuation_noise(line: str) -> bool:- """Allow only page/header noise between split table parts."""- text = line.strip()- if not text:- return True- if text.startswith("<!-- Page ") and text.endswith("-->"):- return True- if re.fullmatch(r'\d+', text):- return True- if "重庆大学硕士学位论文" in text:- return True- continuation_labels = [- "营改增",- "深化增值税改革",- "国有企业",- "非国有企业",- ]- return any(label in text for label in continuation_labels)+def _is_page_marker(text: str) -> bool:+ """Return whether a stripped line is the converter's page-break marker."""+ return text.startswith("<!-- Page ") and text.endswith("-->")+++def _is_table_continuation_gap(lines: list[str]) -> bool:+ """Return whether only page-break furniture separates two table parts.++ A bare number is a printed page number only when the gap crosses a+ ``<!-- Page N -->`` marker; anywhere else it is content (a quantity, a year).+ """+ texts = [line.strip() for line in lines if line.strip()]+ if not any(_is_page_marker(text) for text in texts):+ return not texts+ return all(+ _is_page_marker(text) or PRINTED_PAGE_NUMBER_RE.fullmatch(text)+ for text in texts+ )def _read_markdown_table_block(lines: list[str], start: int) -> tuple[list[str], int]:@@ -1479,32 +1470,22 @@ def merge_markdown_continuation_tables(markdown: str) -> str:index += 1continue- table, table_end = _read_markdown_table_block(lines, index)- search = table_end+ table, index = _read_markdown_table_block(lines, index)while True:- between_start = search- while search < len(lines) and not _is_markdown_table_line(lines[search]):- if not _is_table_continuation_noise(lines[search]):- break- search += 1-- if search >= len(lines) or not _is_markdown_table_line(lines[search]):- break- if any(- not _is_table_continuation_noise(line)- for line in lines[between_start:search]- ):+ next_start = index+ while next_start < len(lines) and not _is_markdown_table_line(lines[next_start]):+ next_start += 1+ if next_start >= len(lines) or not _is_table_continuation_gap(lines[index:next_start]):break- next_table, next_end = _read_markdown_table_block(lines, search)+ next_table, next_end = _read_markdown_table_block(lines, next_start)if not _compatible_table_headers(table, next_table):breaktable.extend(next_table[2:])- search = next_end+ index = next_endresult.extend(table)- index = search if search != table_end else table_endreturn "\n".join(result)diff --git a/skills/ppt-master/scripts/tests/test_pdf_table_continuation.py b/skills/ppt-master/scripts/tests/test_pdf_table_continuation.pynew file mode 100644index 00000000..4a5d9c5f--- /dev/null+++ b/skills/ppt-master/scripts/tests/test_pdf_table_continuation.py@@ -0,0 +1,56 @@+#!/usr/bin/env python3+"""Regression tests for merging PDF tables split across a page break.++Only page-break furniture may separate two halves of one table; a numeric or+labelled paragraph between same-header tables is content and must survive.+"""++from __future__ import annotations++import sys+import unittest+from pathlib import Path++SCRIPTS_DIR = Path(__file__).resolve().parents[1]+BACKEND_DIR = SCRIPTS_DIR / "source_to_md"+if str(BACKEND_DIR) not in sys.path:+ sys.path.insert(0, str(BACKEND_DIR))++import pdf_to_md # noqa: E402++FIRST = "| A | B | C |\n|---|---|---|\n| one | two | three |"+SECOND = "| A | B | C |\n|---|---|---|\n| four | five | six |"+MERGED = "| A | B | C |\n|---|---|---|\n| one | two | three |\n| four | five | six |"+++def _merge(markdown: str) -> str:+ return pdf_to_md.merge_markdown_continuation_tables(markdown)+++class ContinuationMergeTests(unittest.TestCase):+ def test_page_break_with_printed_page_number_merges(self) -> None:+ source = f"{FIRST}\n\n12\n\n<!-- Page 3 -->\n\n{SECOND}"+ self.assertEqual(_merge(source), MERGED)++ def test_blank_gap_merges(self) -> None:+ self.assertEqual(_merge(f"{FIRST}\n\n{SECOND}"), MERGED)++ def test_numeric_paragraph_without_page_break_is_kept(self) -> None:+ for number in ("3000000", "2026", "42"):+ with self.subTest(number=number):+ source = f"{FIRST}\n{number}\n{SECOND}"+ self.assertEqual(_merge(source), source)++ def test_long_number_at_page_break_is_kept(self) -> None:+ source = f"{FIRST}\n\n3000000\n\n<!-- Page 3 -->\n\n{SECOND}"+ self.assertEqual(_merge(source), source)++ def test_label_paragraph_between_tables_is_kept(self) -> None:+ source = f"{FIRST}\n\n国有企业\n\n<!-- Page 3 -->\n\n{SECOND}"+ self.assertEqual(_merge(source), source)++ def test_lines_after_a_lone_table_are_kept(self) -> None:+ for tail in ("\n\nSome text", "\n\n2026\n\nSome text", "\n\n<!-- Page 2 -->\n\n7"):+ with self.subTest(tail=tail):+ source = FIRST + tail+ self.assertEqual(_merge(source), source)