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 <yashiel@skyner.co.za>
This commit is contained in:
Yashiel Sookdeo 2026-06-13 21:15:54 +02:00 committed by kshitij
parent cf7bf5bdc9
commit 24a4df9cd1
2 changed files with 6 additions and 24 deletions

View file

@ -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(

View file

@ -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: