Spaces:
Running
Running
File size: 1,814 Bytes
0157ac7 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 | """Platform rendering profiles for messaging transcripts and status text."""
from __future__ import annotations
from collections.abc import Callable
from dataclasses import dataclass
from messaging.rendering.discord_markdown import (
discord_bold,
discord_code_inline,
escape_discord,
escape_discord_code,
render_markdown_to_discord,
)
from messaging.rendering.discord_markdown import (
format_status as format_status_discord,
)
from messaging.rendering.telegram_markdown import (
escape_md_v2,
escape_md_v2_code,
mdv2_bold,
mdv2_code_inline,
render_markdown_to_mdv2,
)
from messaging.rendering.telegram_markdown import (
format_status as format_status_telegram,
)
from messaging.transcript import RenderCtx
@dataclass(frozen=True, slots=True)
class RenderingProfile:
format_status: Callable[[str, str, str | None], str]
parse_mode: str | None
render_ctx: RenderCtx
limit_chars: int
def build_rendering_profile(platform_name: str) -> RenderingProfile:
"""Return rendering rules for a messaging platform."""
is_discord = platform_name == "discord"
return RenderingProfile(
format_status=format_status_discord if is_discord else format_status_telegram,
parse_mode=None if is_discord else "MarkdownV2",
render_ctx=RenderCtx(
bold=discord_bold if is_discord else mdv2_bold,
code_inline=discord_code_inline if is_discord else mdv2_code_inline,
escape_code=escape_discord_code if is_discord else escape_md_v2_code,
escape_text=escape_discord if is_discord else escape_md_v2,
render_markdown=render_markdown_to_discord
if is_discord
else render_markdown_to_mdv2,
),
limit_chars=1900 if is_discord else 3900,
)
|