Protect link URLs from Telegram inline formatting
Build custom container images / build (map[base_image:php:8-fpm-alpine build_args:PHP_VERSION=8
context:php8-pgsql fingerprint_command:{ apk info -v | LC_ALL=C sort; find /usr/local/lib/php/extensions /usr/local/etc/php/conf.d -type f -exec sha256sum {} + | LC_ALL=C sort; }
name:ph… (push) Successful in 39s
Build custom container images / build (map[base_image:postgres:18 build_args:PG_VERSION=18
POSTGIS_VERSION=3
VCHORD_VERSION=0.5.3
context:postgres fingerprint_command:{ dpkg-query -W -f='${binary:Package}=${Version}\n' | LC_ALL=C sort; find /usr/lib/postgresql -type f -exec sha256su… (push) Successful in 48s
Build custom container images / build (map[base_image:python:3 build_args:PYTHON_VERSION=3
context:python-tools fingerprint_command:{ dpkg-query -W -f='${binary:Package}=${Version}\n' | LC_ALL=C sort; pip freeze | LC_ALL=C sort; }
name:python-tools oci_labels:org.opencontainers.ima… (push) Failing after 1m48s
Build custom container images / build (map[base_image:python:3.12-slim build_args:PYTHON_VERSION=3.12-slim
context:linkki-tiedotus fingerprint_command:{ dpkg-query -W -f='${binary:Package}=${Version}\n' | LC_ALL=C sort; pip freeze | LC_ALL=C sort; }
name:linkki-tiedotus oci_labels:… (push) Successful in 26s
Build custom container images / build (map[base_image:python:3.12-slim build_args:PYTHON_VERSION=3.12-slim
context:timepoll fingerprint_command:{ dpkg-query -W -f='${binary:Package}=${Version}\n' | LC_ALL=C sort; pip freeze | LC_ALL=C sort; }
name:timepoll oci_labels:org.opencontai… (push) Successful in 34s
Build custom container images / build (map[base_image:php:8-fpm-alpine build_args:PHP_VERSION=8
context:php8-pgsql fingerprint_command:{ apk info -v | LC_ALL=C sort; find /usr/local/lib/php/extensions /usr/local/etc/php/conf.d -type f -exec sha256sum {} + | LC_ALL=C sort; }
name:ph… (push) Successful in 39s
Build custom container images / build (map[base_image:postgres:18 build_args:PG_VERSION=18
POSTGIS_VERSION=3
VCHORD_VERSION=0.5.3
context:postgres fingerprint_command:{ dpkg-query -W -f='${binary:Package}=${Version}\n' | LC_ALL=C sort; find /usr/lib/postgresql -type f -exec sha256su… (push) Successful in 48s
Build custom container images / build (map[base_image:python:3 build_args:PYTHON_VERSION=3
context:python-tools fingerprint_command:{ dpkg-query -W -f='${binary:Package}=${Version}\n' | LC_ALL=C sort; pip freeze | LC_ALL=C sort; }
name:python-tools oci_labels:org.opencontainers.ima… (push) Failing after 1m48s
Build custom container images / build (map[base_image:python:3.12-slim build_args:PYTHON_VERSION=3.12-slim
context:linkki-tiedotus fingerprint_command:{ dpkg-query -W -f='${binary:Package}=${Version}\n' | LC_ALL=C sort; pip freeze | LC_ALL=C sort; }
name:linkki-tiedotus oci_labels:… (push) Successful in 26s
Build custom container images / build (map[base_image:python:3.12-slim build_args:PYTHON_VERSION=3.12-slim
context:timepoll fingerprint_command:{ dpkg-query -W -f='${binary:Package}=${Version}\n' | LC_ALL=C sort; pip freeze | LC_ALL=C sort; }
name:timepoll oci_labels:org.opencontai… (push) Successful in 34s
This commit is contained in:
1 parent
8a73c13b12
commit
e54f56d910
2 files changed
+65
-8
No files matched your search
@@ -95,7 +95,18 @@ def markdown_subset_to_html(markdown_text: str) -> str:
|
||||
escaped_text = _map_blockquotes(escaped_text)
|
||||
escaped_text = _map_headings(escaped_text)
|
||||
escaped_text = _map_lists(escaped_text)
|
||||
escaped_text = _map_standard_links(escaped_text)
|
||||
escaped_text, link_token_values = _stash_standard_links(escaped_text)
|
||||
escaped_text = _map_inline_styles(escaped_text)
|
||||
for token, value in link_token_values.items():
|
||||
escaped_text = escaped_text.replace(token, value)
|
||||
for token, value in escape_token_values.items():
|
||||
escaped_text = escaped_text.replace(token, value)
|
||||
for token, value in code_token_values.items():
|
||||
escaped_text = escaped_text.replace(token, value)
|
||||
return escaped_text
|
||||
|
||||
|
||||
def _map_inline_styles(escaped_text: str) -> str:
|
||||
escaped_text = _map_style_pairs(escaped_text, r"\|\|([\s\S]+?)\|\|", "tg-spoiler")
|
||||
escaped_text = _map_style_pairs(escaped_text, r"\*\*(.+?)\*\*", "b")
|
||||
escaped_text = _map_style_pairs(escaped_text, r"__(.+?)__", "b")
|
||||
@@ -103,10 +114,6 @@ def markdown_subset_to_html(markdown_text: str) -> str:
|
||||
escaped_text = _map_style_pairs(escaped_text, r"~~(.+?)~~", "s")
|
||||
escaped_text = _map_style_pairs(escaped_text, r"(?<!\*)\*([^*\n]+)\*(?!\*)", "i")
|
||||
escaped_text = _map_style_pairs(escaped_text, r"(?<!_)_([^_\n]+)_(?!_)", "i")
|
||||
for token, value in escape_token_values.items():
|
||||
escaped_text = escaped_text.replace(token, value)
|
||||
for token, value in code_token_values.items():
|
||||
escaped_text = escaped_text.replace(token, value)
|
||||
return escaped_text
|
||||
|
||||
|
||||
@@ -208,13 +215,20 @@ def _list_indent(level: int) -> str:
|
||||
return "\u00a0" * (level * 4)
|
||||
|
||||
|
||||
def _map_standard_links(text: str) -> str:
|
||||
def _stash_standard_links(text: str) -> tuple[str, dict[str, str]]:
|
||||
token_values: dict[str, str] = {}
|
||||
|
||||
def repl(match: re.Match[str]) -> str:
|
||||
label = match.group(1)
|
||||
url = match.group(2)
|
||||
return f'<a href="{html.escape(url, quote=True)}">{label}</a>'
|
||||
# URL labels and destinations are literal, not inline Markdown.
|
||||
if label != url and not re.match(r"[a-z][a-z0-9+.-]*://", label, re.IGNORECASE):
|
||||
label = _map_inline_styles(label)
|
||||
token = f"ZZLINK{len(token_values)}ZZ"
|
||||
token_values[token] = f'<a href="{html.escape(html.unescape(url), quote=True)}">{label}</a>'
|
||||
return token
|
||||
|
||||
return re.sub(r"\[([^\]]+)\]\(([^)\s]+)\)", repl, text)
|
||||
return re.sub(r"\[([^\]]+)\]\(([^)\s]+)\)", repl, text), token_values
|
||||
|
||||
|
||||
def _map_style_pairs(text: str, pattern: str, html_tag: str) -> str:
|
||||
|
||||
Reference in new issue
Block a user