chatgpt-md-converter 0.3.4__py3-none-any.whl → 0.3.5__py3-none-any.whl
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.
- chatgpt_md_converter/extractors.py +8 -2
- chatgpt_md_converter/telegram_formatter.py +9 -12
- {chatgpt_md_converter-0.3.4.dist-info → chatgpt_md_converter-0.3.5.dist-info}/METADATA +1 -1
- chatgpt_md_converter-0.3.5.dist-info/RECORD +11 -0
- {chatgpt_md_converter-0.3.4.dist-info → chatgpt_md_converter-0.3.5.dist-info}/WHEEL +1 -1
- chatgpt_md_converter-0.3.4.dist-info/RECORD +0 -11
- {chatgpt_md_converter-0.3.4.dist-info → chatgpt_md_converter-0.3.5.dist-info}/licenses/LICENSE +0 -0
- {chatgpt_md_converter-0.3.4.dist-info → chatgpt_md_converter-0.3.5.dist-info}/top_level.txt +0 -0
|
@@ -27,13 +27,19 @@ def extract_and_convert_code_blocks(text: str):
|
|
|
27
27
|
def replacer(match):
|
|
28
28
|
language = match.group(1) if match.group(1) else ""
|
|
29
29
|
code_content = match.group(3)
|
|
30
|
+
|
|
31
|
+
# Properly escape HTML entities in code content
|
|
32
|
+
escaped_content = (
|
|
33
|
+
code_content.replace("&", "&").replace("<", "<").replace(">", ">")
|
|
34
|
+
)
|
|
35
|
+
|
|
30
36
|
placeholder = f"CODEBLOCKPLACEHOLDER{len(placeholders)}"
|
|
31
37
|
placeholders.append(placeholder)
|
|
32
38
|
if not language:
|
|
33
|
-
html_code_block = f"<pre><code>{
|
|
39
|
+
html_code_block = f"<pre><code>{escaped_content}</code></pre>"
|
|
34
40
|
else:
|
|
35
41
|
html_code_block = (
|
|
36
|
-
f'<pre><code class="language-{language}">{
|
|
42
|
+
f'<pre><code class="language-{language}">{escaped_content}</code></pre>'
|
|
37
43
|
)
|
|
38
44
|
return (placeholder, html_code_block)
|
|
39
45
|
|
|
@@ -35,18 +35,14 @@ def telegram_format(text: str) -> str:
|
|
|
35
35
|
# Step 0: Combine blockquotes
|
|
36
36
|
text = combine_blockquotes(text)
|
|
37
37
|
|
|
38
|
-
# Step 1:
|
|
39
|
-
text = convert_html_chars(text)
|
|
40
|
-
|
|
41
|
-
# Step 2: Extract and convert triple-backtick code blocks first
|
|
38
|
+
# Step 1: Extract and convert triple-backtick code blocks first
|
|
42
39
|
output, triple_code_blocks = extract_and_convert_code_blocks(text)
|
|
43
40
|
|
|
44
|
-
# Step 2
|
|
41
|
+
# Step 2: Extract inline code snippets
|
|
45
42
|
output, inline_code_snippets = extract_inline_code_snippets(output)
|
|
46
43
|
|
|
47
|
-
# Step 3:
|
|
48
|
-
|
|
49
|
-
output = output.replace("<", "<").replace(">", ">")
|
|
44
|
+
# Step 3: Convert HTML reserved symbols in the text (not in code blocks)
|
|
45
|
+
output = convert_html_chars(output)
|
|
50
46
|
|
|
51
47
|
# Convert headings (H1-H6)
|
|
52
48
|
output = re.sub(r"^(#{1,6})\s+(.+)$", r"<b>\2</b>", output, flags=re.MULTILINE)
|
|
@@ -80,20 +76,21 @@ def telegram_format(text: str) -> str:
|
|
|
80
76
|
link_pattern = r"(?:!?)\[((?:[^\[\]]|\[.*?\])*)\]\(([^)]+)\)"
|
|
81
77
|
output = re.sub(link_pattern, r'<a href="\2">\1</a>', output)
|
|
82
78
|
|
|
83
|
-
# Step
|
|
79
|
+
# Step 4: Reinsert inline code snippets, applying HTML escaping to the content
|
|
84
80
|
for placeholder, snippet in inline_code_snippets.items():
|
|
81
|
+
# Apply HTML escaping to the content of inline code
|
|
85
82
|
escaped_snippet = (
|
|
86
83
|
snippet.replace("&", "&").replace("<", "<").replace(">", ">")
|
|
87
84
|
)
|
|
88
85
|
output = output.replace(placeholder, f"<code>{escaped_snippet}</code>")
|
|
89
86
|
|
|
90
|
-
# Step
|
|
87
|
+
# Step 5: Reinsert the converted triple-backtick code blocks
|
|
91
88
|
output = reinsert_code_blocks(output, triple_code_blocks)
|
|
92
89
|
|
|
93
|
-
# Step
|
|
90
|
+
# Step 6: Remove blockquote escaping
|
|
94
91
|
output = remove_blockquote_escaping(output)
|
|
95
92
|
|
|
96
|
-
# Step
|
|
93
|
+
# Step 7: Remove spoiler tag escaping
|
|
97
94
|
output = remove_spoiler_escaping(output)
|
|
98
95
|
|
|
99
96
|
# Clean up multiple consecutive newlines, but preserve intentional spacing
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
chatgpt_md_converter/__init__.py,sha256=AfkikySkXsJ8HKQcSlU7B1KBHz54QCGJ7MO5Ka9oWRM,79
|
|
2
|
+
chatgpt_md_converter/converters.py,sha256=fgebhbhMcIOqnr0xuV04v81RD91FfaGfA0kO417cDqc,831
|
|
3
|
+
chatgpt_md_converter/extractors.py,sha256=WU38iAG-MANmilqR73gAvxqqXvx4JT8q3xrac_GRXGI,2071
|
|
4
|
+
chatgpt_md_converter/formatters.py,sha256=UbjRG7bLETIGDaFDbFybwW8dKYBMDmgLmIasJiw_j60,2304
|
|
5
|
+
chatgpt_md_converter/helpers.py,sha256=2Nc9_s0HcLq79mBt7Hje19LzbO6z9mUNgayoMyWkIhI,874
|
|
6
|
+
chatgpt_md_converter/telegram_formatter.py,sha256=YlWW8JUlXqP_3chz53_kj15o4d2uW0RlVsuJVcCrzic,3872
|
|
7
|
+
chatgpt_md_converter-0.3.5.dist-info/licenses/LICENSE,sha256=SDr2jeP-s2g4vf17-jdLXrrqA4_mU7L_RtSJlv4Y2mk,1077
|
|
8
|
+
chatgpt_md_converter-0.3.5.dist-info/METADATA,sha256=ly_GTnX933MbdUCZKKQAn3kQrICrRiCWvgaJ1dBgWCc,5785
|
|
9
|
+
chatgpt_md_converter-0.3.5.dist-info/WHEEL,sha256=ck4Vq1_RXyvS4Jt6SI0Vz6fyVs4GWg7AINwpsaGEgPE,91
|
|
10
|
+
chatgpt_md_converter-0.3.5.dist-info/top_level.txt,sha256=T2o7csVtZgr-Pwm83aSUkZn0humJmDFNqW38tRSsNqw,21
|
|
11
|
+
chatgpt_md_converter-0.3.5.dist-info/RECORD,,
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
chatgpt_md_converter/__init__.py,sha256=AfkikySkXsJ8HKQcSlU7B1KBHz54QCGJ7MO5Ka9oWRM,79
|
|
2
|
-
chatgpt_md_converter/converters.py,sha256=fgebhbhMcIOqnr0xuV04v81RD91FfaGfA0kO417cDqc,831
|
|
3
|
-
chatgpt_md_converter/extractors.py,sha256=RNwo57_6jCe-HoX5eCvvZcjSTc2uPax-6QEtXqXA5QQ,1880
|
|
4
|
-
chatgpt_md_converter/formatters.py,sha256=UbjRG7bLETIGDaFDbFybwW8dKYBMDmgLmIasJiw_j60,2304
|
|
5
|
-
chatgpt_md_converter/helpers.py,sha256=2Nc9_s0HcLq79mBt7Hje19LzbO6z9mUNgayoMyWkIhI,874
|
|
6
|
-
chatgpt_md_converter/telegram_formatter.py,sha256=L0ESIY1AOuRXdIto2lWR38zuYuIwlLBScGINMrm8VVk,4091
|
|
7
|
-
chatgpt_md_converter-0.3.4.dist-info/licenses/LICENSE,sha256=SDr2jeP-s2g4vf17-jdLXrrqA4_mU7L_RtSJlv4Y2mk,1077
|
|
8
|
-
chatgpt_md_converter-0.3.4.dist-info/METADATA,sha256=mOr7k13cT9qf7bb0OOgF-1bgU7EEyzPvKlzDoEIx5Sc,5785
|
|
9
|
-
chatgpt_md_converter-0.3.4.dist-info/WHEEL,sha256=CmyFI0kx5cdEMTLiONQRbGQwjIoR1aIYB7eCAQ4KPJ0,91
|
|
10
|
-
chatgpt_md_converter-0.3.4.dist-info/top_level.txt,sha256=T2o7csVtZgr-Pwm83aSUkZn0humJmDFNqW38tRSsNqw,21
|
|
11
|
-
chatgpt_md_converter-0.3.4.dist-info/RECORD,,
|
{chatgpt_md_converter-0.3.4.dist-info → chatgpt_md_converter-0.3.5.dist-info}/licenses/LICENSE
RENAMED
|
File without changes
|
|
File without changes
|