Skip to content

Commit

Permalink
Optimize markdown display, leave a blank line before and after code b…
Browse files Browse the repository at this point in the history
…locks.
  • Loading branch information
yym68686 committed Jun 25, 2024
1 parent 52bc919 commit 745a991
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 7 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
build
*.egg-info
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

setup(
name="md2tgmd",
version="0.2.3",
version="0.2.4",
description="md2tgmd is a Markdown to Telegram-specific-markdown converter.",
long_description=Path.open(Path("README.md"), encoding="utf-8").read(),
long_description_content_type="text/markdown",
Expand Down
12 changes: 6 additions & 6 deletions src/md2tgmd.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ def escape_all_backquote(text):

def dedent_space(text):
import textwrap
return textwrap.dedent(text)
return "\n\n" + textwrap.dedent(text).strip() + "\n\n"

def find_lines_with_char(s, char, min_count):
"""
Expand Down Expand Up @@ -138,7 +138,7 @@ def escape(text, flag=0):
text = re.sub(r"\.", '\.', text)
text = re.sub(r"!", '\!', text)
text = find_lines_with_char(text, '`', 5)
text = replace_all(text, r"(\x20*```[\D\d\s]+?```)", dedent_space)
text = replace_all(text, r"(\n+\x20*```[\D\d\s]+?```\n+)", dedent_space)
return text

text = r'''
Expand Down Expand Up @@ -173,17 +173,17 @@ def escape(text, flag=0):
2. item 2
1. item 1
2. item 2
sudo apt install mesa-utils # 安装
```python
# comment
print("1.1\n")_
\subsubsection{1.1}
- item 1 -
```
2. item 2
sudo apt install mesa-utils # 安装
\subsubsection{1.1}
And simple text `with-ten` `with+ten` + some - **symbols**. # `with-ten`里面的`-`不会被转义
Expand Down

0 comments on commit 745a991

Please sign in to comment.