From 24a4df9cd11598ec41c0bbb1f85369ff06d234e5 Mon Sep 17 00:00:00 2001 From: Yashiel Sookdeo Date: Sat, 13 Jun 2026 21:15:54 +0200 Subject: [PATCH] refactor(telegram): import shared table-detection primitives from helpers.py Replace local _TABLE_SEPARATOR_RE, _is_table_row, and _split_markdown_table_row with imports from the shared module. Telegram-specific rendering stays local. Co-authored-by: Yashiel Sookdeo --- plugins/platforms/discord/adapter.py | 3 +-- plugins/platforms/telegram/adapter.py | 27 +++++---------------------- 2 files changed, 6 insertions(+), 24 deletions(-) diff --git a/plugins/platforms/discord/adapter.py b/plugins/platforms/discord/adapter.py index 65c96b01a93..d4ae59843bc 100644 --- a/plugins/platforms/discord/adapter.py +++ b/plugins/platforms/discord/adapter.py @@ -102,7 +102,7 @@ sys.path.insert(0, str(_Path(__file__).resolve().parents[3])) from gateway.config import Platform, PlatformConfig -from gateway.platforms.helpers import MessageDeduplicator, ThreadParticipationTracker +from gateway.platforms.helpers import MessageDeduplicator, ThreadParticipationTracker, convert_table_to_bullets from utils import atomic_json_write, env_float from gateway.platforms.base import ( BasePlatformAdapter, @@ -3418,7 +3418,6 @@ class DiscordAdapter(BasePlatformAdapter): """ if not content: return content - from gateway.platforms.helpers import convert_table_to_bullets return convert_table_to_bullets(content) async def _run_simple_slash( diff --git a/plugins/platforms/telegram/adapter.py b/plugins/platforms/telegram/adapter.py index 8ae46cdd358..6f89b9aed00 100644 --- a/plugins/platforms/telegram/adapter.py +++ b/plugins/platforms/telegram/adapter.py @@ -220,31 +220,14 @@ def _separate_chunk_indicator_from_fence(text: str) -> str: # Reformating each row into a bold heading plus bullet list keeps the content # readable on mobile clients while preserving the source data. -# Matches a GFM table delimiter row: optional outer pipes, cells containing -# only dashes (with optional leading/trailing colons for alignment) separated -# by '|'. Requires at least one internal '|' so lone '---' horizontal rules -# are NOT matched. -_TABLE_SEPARATOR_RE = re.compile( - r'^\s*\|?\s*:?-+:?\s*(?:\|\s*:?-+:?\s*){1,}\|?\s*$' +# Table detection primitives are shared with Discord via gateway.platforms.helpers. +from gateway.platforms.helpers import ( + TABLE_SEPARATOR_RE as _TABLE_SEPARATOR_RE, + is_table_row as _is_table_row, + split_markdown_table_row as _split_markdown_table_row, ) -def _is_table_row(line: str) -> bool: - """Return True if *line* could plausibly be a table data row.""" - stripped = line.strip() - return bool(stripped) and '|' in stripped - - -def _split_markdown_table_row(line: str) -> list[str]: - """Split a simple GFM table row into stripped cell values.""" - stripped = line.strip() - if stripped.startswith("|"): - stripped = stripped[1:] - if stripped.endswith("|"): - stripped = stripped[:-1] - return [cell.strip() for cell in stripped.split("|")] - - def _render_table_block_for_telegram(table_block: list[str]) -> str: """Render a detected GFM table as Telegram-friendly row groups.""" if len(table_block) < 3: