423
Some checks failed
CI / Lint (ruff + mypy) (push) Failing after 32s
CI / Run tests (push) Has been skipped
CI / Docker build test (push) Successful in 10s

This commit is contained in:
2026-04-02 21:16:05 +07:00
parent d193d2c930
commit 0626454253
3 changed files with 24 additions and 29 deletions

View File

@@ -1,5 +1,7 @@
from __future__ import annotations
from html import escape
DEFAULT_STATUS_LABELS = {
"open": "исполняет роль",
@@ -8,23 +10,13 @@ DEFAULT_STATUS_LABELS = {
"rest": "антракт",
}
MARKDOWN_V2_SPECIALS = r"_*[]()~`>#+-=|{}.!"
def escape_markdown_v2(value: str) -> str:
return "".join(f"\\{char}" if char in MARKDOWN_V2_SPECIALS else char for char in value)
def escape_markdown_v2_url(value: str) -> str:
return value.replace("\\", "\\\\").replace(")", "\\)")
def build_hidden_link(config: dict) -> str:
url = config.get("hidden_link_url", "").strip()
if not url:
return ""
invisible = config.get("hidden_link_char", "\u2063")
return f"[{invisible}]({escape_markdown_v2_url(url)})"
invisible = config.get("hidden_link_char", "​")
return f'<a href="{escape(url, quote=True)}">{invisible}</a>'
def build_actor_lines(config: dict, state: dict) -> str:
@@ -37,21 +29,20 @@ def build_actor_lines(config: dict, state: dict) -> str:
status = current.get("status", actor.get("default_status", "backstage"))
phrase = current.get("phrase", actor.get("phrases", {}).get(status, ""))
label = status_labels.get(status, status)
display_name = actor.get("display_md", actor["display_name"])
meta = actor.get("meta_md", actor["pronouns"])
emoji = actor.get("emoji_md", actor.get("emoji", ""))
display_name = actor.get("display_html", escape(actor["display_name"]))
meta = actor.get("meta_html", escape(actor["pronouns"]))
emoji = actor.get("emoji_html", escape(actor.get("emoji", "")))
line = (
f"{emoji} "
f"[{escape_markdown_v2(display_name)}]({escape_markdown_v2_url(actor['link'])}) "
f"{escape_markdown_v2(meta)} "
f"{escape_markdown_v2(label)}\\."
f'{emoji} '
f'<a href="{escape(actor["link"], quote=True)}">{display_name}</a>'
f"{meta}{escape(label)}."
)
if phrase:
line = f"{line}\n {escape_markdown_v2(phrase)}"
line = f"{line}\n {escape(phrase)}"
actor_lines.append(line)
actor_lines.extend(config.get("static_actor_lines_md", []))
actor_lines.extend(config.get("static_actor_lines_html", []))
return "\n".join(actor_lines)
@@ -61,17 +52,17 @@ def build_default_template(config: dict) -> str:
if hidden:
blocks.append(hidden)
for key in ("header", "intro_links", "projects_block", "actors_title"):
for key in ("header_html", "intro_links_html", "projects_block_html", "actors_title_html"):
value = config.get(key, "").strip()
if value:
blocks.append(escape_markdown_v2(value))
blocks.append(value)
blocks.append("{{actors}}")
for key in ("legend", "footer"):
for key in ("legend_html", "footer_html"):
value = config.get(key, "").strip()
if value:
blocks.append(escape_markdown_v2(value))
blocks.append(value)
return "\n\n".join(blocks)