chatgpt-md-converter 0.3.11__tar.gz → 0.3.12__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 (28) hide show
  1. {chatgpt_md_converter-0.3.11 → chatgpt_md_converter-0.3.12}/PKG-INFO +1 -1
  2. {chatgpt_md_converter-0.3.11 → chatgpt_md_converter-0.3.12}/chatgpt_md_converter/html_markdown/handlers.py +3 -2
  3. {chatgpt_md_converter-0.3.11 → chatgpt_md_converter-0.3.12}/chatgpt_md_converter/telegram_markdown/preprocess.py +4 -0
  4. {chatgpt_md_converter-0.3.11 → chatgpt_md_converter-0.3.12}/chatgpt_md_converter/telegram_markdown/renderer.py +1 -2
  5. {chatgpt_md_converter-0.3.11 → chatgpt_md_converter-0.3.12}/chatgpt_md_converter.egg-info/PKG-INFO +1 -1
  6. {chatgpt_md_converter-0.3.11 → chatgpt_md_converter-0.3.12}/setup.py +1 -1
  7. {chatgpt_md_converter-0.3.11 → chatgpt_md_converter-0.3.12}/tests/test_parser.py +35 -0
  8. {chatgpt_md_converter-0.3.11 → chatgpt_md_converter-0.3.12}/tests/test_roundtrip_markdown.py +7 -0
  9. {chatgpt_md_converter-0.3.11 → chatgpt_md_converter-0.3.12}/LICENSE +0 -0
  10. {chatgpt_md_converter-0.3.11 → chatgpt_md_converter-0.3.12}/README.md +0 -0
  11. {chatgpt_md_converter-0.3.11 → chatgpt_md_converter-0.3.12}/chatgpt_md_converter/__init__.py +0 -0
  12. {chatgpt_md_converter-0.3.11 → chatgpt_md_converter-0.3.12}/chatgpt_md_converter/html_markdown/escaping.py +0 -0
  13. {chatgpt_md_converter-0.3.11 → chatgpt_md_converter-0.3.12}/chatgpt_md_converter/html_markdown/renderer.py +0 -0
  14. {chatgpt_md_converter-0.3.11 → chatgpt_md_converter-0.3.12}/chatgpt_md_converter/html_markdown/state.py +0 -0
  15. {chatgpt_md_converter-0.3.11 → chatgpt_md_converter-0.3.12}/chatgpt_md_converter/html_markdown/tree.py +0 -0
  16. {chatgpt_md_converter-0.3.11 → chatgpt_md_converter-0.3.12}/chatgpt_md_converter/html_splitter.py +0 -0
  17. {chatgpt_md_converter-0.3.11 → chatgpt_md_converter-0.3.12}/chatgpt_md_converter/html_to_markdown.py +0 -0
  18. {chatgpt_md_converter-0.3.11 → chatgpt_md_converter-0.3.12}/chatgpt_md_converter/telegram_formatter.py +0 -0
  19. {chatgpt_md_converter-0.3.11 → chatgpt_md_converter-0.3.12}/chatgpt_md_converter/telegram_markdown/__init__.py +0 -0
  20. {chatgpt_md_converter-0.3.11 → chatgpt_md_converter-0.3.12}/chatgpt_md_converter/telegram_markdown/code_blocks.py +0 -0
  21. {chatgpt_md_converter-0.3.11 → chatgpt_md_converter-0.3.12}/chatgpt_md_converter/telegram_markdown/inline.py +0 -0
  22. {chatgpt_md_converter-0.3.11 → chatgpt_md_converter-0.3.12}/chatgpt_md_converter/telegram_markdown/postprocess.py +0 -0
  23. {chatgpt_md_converter-0.3.11 → chatgpt_md_converter-0.3.12}/chatgpt_md_converter.egg-info/SOURCES.txt +0 -0
  24. {chatgpt_md_converter-0.3.11 → chatgpt_md_converter-0.3.12}/chatgpt_md_converter.egg-info/dependency_links.txt +0 -0
  25. {chatgpt_md_converter-0.3.11 → chatgpt_md_converter-0.3.12}/chatgpt_md_converter.egg-info/top_level.txt +0 -0
  26. {chatgpt_md_converter-0.3.11 → chatgpt_md_converter-0.3.12}/setup.cfg +0 -0
  27. {chatgpt_md_converter-0.3.11 → chatgpt_md_converter-0.3.12}/tests/test_html_to_markdown_inline_spacing.py +0 -0
  28. {chatgpt_md_converter-0.3.11 → chatgpt_md_converter-0.3.12}/tests/test_splitter.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: chatgpt_md_converter
3
- Version: 0.3.11
3
+ Version: 0.3.12
4
4
  Summary: A package for converting markdown to HTML for chat Telegram bots
5
5
  Home-page: https://github.com/botfather-dev/formatter-chatgpt-telegram
6
6
  Author: Kostiantyn Kriuchkov
@@ -169,11 +169,12 @@ def _handle_blockquote(node: Node, state: RenderState) -> str:
169
169
  expandable = "expandable" in node.attrs
170
170
  rendered: list[str] = []
171
171
  for index, line in enumerate(lines):
172
- prefix = "**>" if expandable and index == 0 else ">"
173
172
  stripped = line.rstrip("\r")
174
173
  if expandable:
175
- rendered.append(prefix + stripped)
174
+ marker = ">**" if index == 0 else ">"
175
+ rendered.append(f"{marker} {stripped}" if stripped else marker)
176
176
  else:
177
+ prefix = ">"
177
178
  rendered.append(f"{prefix} {stripped}" if stripped else prefix)
178
179
  return "\n".join(rendered)
179
180
 
@@ -14,6 +14,10 @@ def combine_blockquotes(text: str) -> str:
14
14
  in_blockquote = True
15
15
  is_expandable = True
16
16
  blockquote_lines.append(line[3:].strip())
17
+ elif line.startswith(">**") and (len(line) == 3 or line[3].isspace()):
18
+ in_blockquote = True
19
+ is_expandable = True
20
+ blockquote_lines.append(line[3:].strip())
17
21
  elif line.startswith(">"):
18
22
  if not in_blockquote:
19
23
  in_blockquote = True
@@ -12,9 +12,8 @@ from .preprocess import combine_blockquotes
12
12
 
13
13
 
14
14
  def telegram_format(text: str) -> str:
15
- text = combine_blockquotes(text)
16
-
17
15
  output, block_map = extract_and_convert_code_blocks(text)
16
+ output = combine_blockquotes(output)
18
17
  output, inline_snippets = extract_inline_code_snippets(output)
19
18
 
20
19
  output = convert_html_chars(output)
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: chatgpt_md_converter
3
- Version: 0.3.11
3
+ Version: 0.3.12
4
4
  Summary: A package for converting markdown to HTML for chat Telegram bots
5
5
  Home-page: https://github.com/botfather-dev/formatter-chatgpt-telegram
6
6
  Author: Kostiantyn Kriuchkov
@@ -2,7 +2,7 @@ from setuptools import setup
2
2
 
3
3
  setup(
4
4
  name="chatgpt_md_converter",
5
- version="0.3.11",
5
+ version="0.3.12",
6
6
  author="Kostiantyn Kriuchkov",
7
7
  author_email="latand666@gmail.com",
8
8
  description="A package for converting markdown to HTML for chat Telegram bots",
@@ -716,6 +716,41 @@ Continued</blockquote>"""
716
716
  assert output == expected_output, "Failed handling spoiler inside blockquote"
717
717
 
718
718
 
719
+ def test_blockquote_lines_inside_code_block():
720
+ input_text = """```text
721
+ >** заголовок довгої цитати
722
+ > рядок 2
723
+ > рядок 3
724
+ > рядок 4
725
+ > і ще хоч сто рядків
726
+ ```"""
727
+ expected_output = (
728
+ '<pre><code class="language-text">&gt;** заголовок довгої цитати\n'
729
+ '&gt; рядок 2\n'
730
+ '&gt; рядок 3\n'
731
+ '&gt; рядок 4\n'
732
+ '&gt; і ще хоч сто рядків\n'
733
+ "</code></pre>"
734
+ )
735
+ output = telegram_format(input_text)
736
+ assert output == expected_output, f"Got: {output}"
737
+
738
+
739
+ def test_blockquote_double_asterisk_prefix():
740
+ input_text = """>** заголовок довгої цитати
741
+ > рядок 2
742
+ > рядок 3
743
+ > рядок 4
744
+ > і ще хоч сто рядків"""
745
+ expected_output = """<blockquote expandable>заголовок довгої цитати
746
+ рядок 2
747
+ рядок 3
748
+ рядок 4
749
+ і ще хоч сто рядків</blockquote>"""
750
+ output = telegram_format(input_text)
751
+ assert output == expected_output, f"Got: {output}"
752
+
753
+
719
754
  def test_multiple_spoilers():
720
755
  input_text = "First ||spoiler|| and then another ||spoiler with *italic*||"
721
756
  expected_output = 'First <span class="tg-spoiler">spoiler</span> and then another <span class="tg-spoiler">spoiler with <i>italic</i></span>'
@@ -30,3 +30,10 @@ def test_markdown_html_markdown_cycle_is_idempotent(_case, markdown_input, _):
30
30
  assert '<br' not in html_first
31
31
  assert '<br' not in html_third
32
32
  assert html_first == html_third
33
+
34
+
35
+ def test_html_to_markdown_expandable_blockquote():
36
+ html_text = "<blockquote expandable>заголовок\nрядок 2\nрядок 3</blockquote>"
37
+ expected_markdown = ">** заголовок\n> рядок 2\n> рядок 3"
38
+ markdown = html_to_telegram_markdown(html_text)
39
+ assert markdown == expected_markdown