telegramify-markdown 1.4.2__tar.gz → 1.4.3__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (38) hide show
  1. {telegramify_markdown-1.4.2 → telegramify_markdown-1.4.3}/PKG-INFO +1 -1
  2. {telegramify_markdown-1.4.2 → telegramify_markdown-1.4.3}/pyproject.toml +1 -1
  3. {telegramify_markdown-1.4.2 → telegramify_markdown-1.4.3}/src/telegramify_markdown/rich.py +8 -1
  4. {telegramify_markdown-1.4.2 → telegramify_markdown-1.4.3}/tests/test_rich.py +17 -0
  5. {telegramify_markdown-1.4.2 → telegramify_markdown-1.4.3}/LICENSE +0 -0
  6. {telegramify_markdown-1.4.2 → telegramify_markdown-1.4.3}/README.md +0 -0
  7. {telegramify_markdown-1.4.2 → telegramify_markdown-1.4.3}/src/telegramify_markdown/__init__.py +0 -0
  8. {telegramify_markdown-1.4.2 → telegramify_markdown-1.4.3}/src/telegramify_markdown/code_file.py +0 -0
  9. {telegramify_markdown-1.4.2 → telegramify_markdown-1.4.3}/src/telegramify_markdown/config.py +0 -0
  10. {telegramify_markdown-1.4.2 → telegramify_markdown-1.4.3}/src/telegramify_markdown/content.py +0 -0
  11. {telegramify_markdown-1.4.2 → telegramify_markdown-1.4.3}/src/telegramify_markdown/converter.py +0 -0
  12. {telegramify_markdown-1.4.2 → telegramify_markdown-1.4.3}/src/telegramify_markdown/entity.py +0 -0
  13. {telegramify_markdown-1.4.2 → telegramify_markdown-1.4.3}/src/telegramify_markdown/latex_escape/__init__.py +0 -0
  14. {telegramify_markdown-1.4.2 → telegramify_markdown-1.4.3}/src/telegramify_markdown/latex_escape/const.py +0 -0
  15. {telegramify_markdown-1.4.2 → telegramify_markdown-1.4.3}/src/telegramify_markdown/latex_escape/helper.py +0 -0
  16. {telegramify_markdown-1.4.2 → telegramify_markdown-1.4.3}/src/telegramify_markdown/logger.py +0 -0
  17. {telegramify_markdown-1.4.2 → telegramify_markdown-1.4.3}/src/telegramify_markdown/mdv2.py +0 -0
  18. {telegramify_markdown-1.4.2 → telegramify_markdown-1.4.3}/src/telegramify_markdown/mermaid.py +0 -0
  19. {telegramify_markdown-1.4.2 → telegramify_markdown-1.4.3}/src/telegramify_markdown/pipeline.py +0 -0
  20. {telegramify_markdown-1.4.2 → telegramify_markdown-1.4.3}/src/telegramify_markdown/py.typed +0 -0
  21. {telegramify_markdown-1.4.2 → telegramify_markdown-1.4.3}/src/telegramify_markdown/stream/__init__.py +0 -0
  22. {telegramify_markdown-1.4.2 → telegramify_markdown-1.4.3}/src/telegramify_markdown/stream/core.py +0 -0
  23. {telegramify_markdown-1.4.2 → telegramify_markdown-1.4.3}/src/telegramify_markdown/stream/draft.py +0 -0
  24. {telegramify_markdown-1.4.2 → telegramify_markdown-1.4.3}/src/telegramify_markdown/stream/edit.py +0 -0
  25. {telegramify_markdown-1.4.2 → telegramify_markdown-1.4.3}/src/telegramify_markdown/type.py +0 -0
  26. {telegramify_markdown-1.4.2 → telegramify_markdown-1.4.3}/src/telegramify_markdown/word_count.py +0 -0
  27. {telegramify_markdown-1.4.2 → telegramify_markdown-1.4.3}/tests/exp1.md +0 -0
  28. {telegramify_markdown-1.4.2 → telegramify_markdown-1.4.3}/tests/exp2.md +0 -0
  29. {telegramify_markdown-1.4.2 → telegramify_markdown-1.4.3}/tests/send_showcase.py +0 -0
  30. {telegramify_markdown-1.4.2 → telegramify_markdown-1.4.3}/tests/showcase_latex.py +0 -0
  31. {telegramify_markdown-1.4.2 → telegramify_markdown-1.4.3}/tests/test_converter.py +0 -0
  32. {telegramify_markdown-1.4.2 → telegramify_markdown-1.4.3}/tests/test_entity.py +0 -0
  33. {telegramify_markdown-1.4.2 → telegramify_markdown-1.4.3}/tests/test_mdv2.py +0 -0
  34. {telegramify_markdown-1.4.2 → telegramify_markdown-1.4.3}/tests/test_mermaid.py +0 -0
  35. {telegramify_markdown-1.4.2 → telegramify_markdown-1.4.3}/tests/test_performance.py +0 -0
  36. {telegramify_markdown-1.4.2 → telegramify_markdown-1.4.3}/tests/test_pipeline.py +0 -0
  37. {telegramify_markdown-1.4.2 → telegramify_markdown-1.4.3}/tests/test_server.py +0 -0
  38. {telegramify_markdown-1.4.2 → telegramify_markdown-1.4.3}/tests/test_stream.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: telegramify-markdown
3
- Version: 1.4.2
3
+ Version: 1.4.3
4
4
  Summary: Convert Markdown to Telegram plain text + MessageEntity pairs
5
5
  Author-Email: sudoskys <coldlando@hotmail.com>
6
6
  License: MIT
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "telegramify-markdown"
3
- version = "1.4.2"
3
+ version = "1.4.3"
4
4
  description = "Convert Markdown to Telegram plain text + MessageEntity pairs"
5
5
  authors = [
6
6
  { name = "sudoskys", email = "coldlando@hotmail.com" },
@@ -1113,8 +1113,15 @@ def _extract_wrapped_text(html_text: str, tag: str) -> str | None:
1113
1113
  return None
1114
1114
 
1115
1115
 
1116
+ # A code block with a language and one without are matched separately: a single
1117
+ # pattern with a greedy body and an alternated close tag settles on "</pre>" and
1118
+ # leaves "</code>" in the body, which then gets escaped into visible text.
1119
+ _PRE_CODE_RE = re.compile(r'(<pre><code class="[^"]+">)(.*)(</code></pre>)', re.DOTALL)
1120
+ _PRE_RE = re.compile(r"(<pre>)(.*)(</pre>)", re.DOTALL)
1121
+
1122
+
1116
1123
  def _extract_pre_text(html_text: str) -> tuple[str, str, str] | None:
1117
- match = re.fullmatch(r"(<pre(?:><code class=\"[^\"]+\">|>))(.*)(</code></pre>|</pre>)", html_text, re.DOTALL)
1124
+ match = _PRE_CODE_RE.fullmatch(html_text) or _PRE_RE.fullmatch(html_text)
1118
1125
  if not match:
1119
1126
  return None
1120
1127
  return match.group(1), match.group(2), match.group(3)
@@ -312,6 +312,23 @@ class SplitRichTest(unittest.TestCase):
312
312
  self.assertTrue(html.endswith("</pre>"))
313
313
  self.assertLessEqual(len(html.encode("utf-8")), 32768)
314
314
 
315
+ def test_html_mode_splits_oversized_pre_block_with_language(self):
316
+ """带语言的超长 code block 每个 chunk 都以 </code></pre> 闭合,且不泄漏 </code> 文本。"""
317
+ code = "\n".join(f"x_{n} = {n}" for n in range(4000))
318
+ result = telegramify_rich(f"```python\n{code}\n```")
319
+
320
+ self.assertGreater(len(result), 1)
321
+ open_tag = '<pre><code class="language-python">'
322
+ recovered = []
323
+ for item in result:
324
+ html = item.to_dict()["html"]
325
+ self.assertTrue(html.startswith(open_tag))
326
+ self.assertTrue(html.endswith("</code></pre>"))
327
+ self.assertNotIn("&lt;/code&gt;", html)
328
+ self.assertLessEqual(len(html.encode("utf-8")), 32768)
329
+ recovered.append(unescape(html.removeprefix(open_tag).removesuffix("</code></pre>")))
330
+ self.assertEqual("".join(recovered), code)
331
+
315
332
  def test_html_mode_splits_oversized_escaped_pre_block(self):
316
333
  """超长 code block 含 HTML 特殊字符时保持可见文本。"""
317
334
  visible = "<&>" * 12000