fix(telegram): support <code> blocks wrapped in <pre> for syntax highlighting (#1423)

This commit is contained in:
David
2025-10-05 07:54:27 -07:00
committed by GitHub
parent a3b4a13b5c
commit fe000d0884
3 changed files with 4 additions and 15 deletions

View File

@@ -307,19 +307,6 @@ class NotifyTelegram(NotifyBase):
" -",
{},
),
# convert pre tags to code (supported by Telegram)
(
re.compile(r"<\s*pre([^a-z0-9>][^>]*)?>", (re.I | re.M | re.S)),
"{}<code>",
{"html": "\r\n"},
),
(
re.compile(
r"<\s*/\s*pre([^a-z0-9>][^>]*)?>", (re.I | re.M | re.S)
),
"</code>{}",
{"html": "\r\n"},
),
# New Lines
(
re.compile(

View File

@@ -1404,7 +1404,8 @@ def test_plugin_telegram_html_formatting(mock_post):
== "\r\n<b>Bootstrap 101 Template</b>\r\n<b>My Title</b>\r\n"
"<b>Heading 1</b>\r\n-Bullet 1\r\n-Bullet 2\r\n-Bullet 3\r\n"
"-Bullet 1\r\n-Bullet 2\r\n-Bullet 3\r\n<b>Heading 2</b>\r\n"
"A div entry\r\nA div entry\r\n<code>A pre entry</code>\r\n"
"A div entry\r\nA div entry\r\n"
"<pre><code class=\"language-python\">print('hello')</code></pre>\r\n"
"<b>Heading 3</b>\r\n<b>Heading 4</b>\r\n<b>Heading 5</b>\r\n"
"<b>Heading 6</b>\r\nA set of text\r\n"
"Another line after the set of text\r\nMore text\r\nlabel"

View File

@@ -44,9 +44,10 @@
<div>A div entry</div>
<p>
<span>A div entry</span>
<pre>A pre entry</pre>
</p>
<pre><code class="language-python">print('hello')</code></pre>
<h3>Heading 3</h3>
<h4>Heading 4</h4>
<h5>Heading 5</h5>