Skip to content

Commit

Permalink
Optimize markdown rendering display, automatically add a blank line b…
Browse files Browse the repository at this point in the history
…elow the title
  • Loading branch information
yym68686 committed May 27, 2024
1 parent d40e66a commit 2556db2
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
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.1",
version="0.2.2",
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
5 changes: 3 additions & 2 deletions src/md2tgmd.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ def replace_all(text, pattern, function):
return ''.join(new_list)

def escapeshape(text):
return '▎*' + " ".join(text.split()[1:]) + '*'
return '▎*' + " ".join(text.split()[1:]) + '*\n\n'

def escapeminus(text):
return '\\' + text
Expand Down Expand Up @@ -101,7 +101,7 @@ def escape(text, flag=0):
text = re.sub(r"\@{3}(.*?)\@{3}\^{3}(.*?)\^{3}", '[\\1](\\2)', text)
text = re.sub(r"~", '\~', text)
text = re.sub(r">", '\>', text)
text = replace_all(text, r"(^#+\s.+?$)|```[\D\d\s]+?```", escapeshape)
text = replace_all(text, r"(^#+\s.+?\n+)|```[\D\d\s]+?```", escapeshape)
text = re.sub(r"#", '\#', text)
text = replace_all(text, r"(\+)|\n[\s]*-\s|```[\D\d\s]+?```|`[\D\d\s]*?`", escapeplus)
text = re.sub(r"\n{1,2}(\s*\d{1,2}\.\s)", '\n\n\\1', text)
Expand Down Expand Up @@ -149,6 +149,7 @@ def escape(text, flag=0):
```
# bn
# b
# Header
Expand Down

0 comments on commit 2556db2

Please sign in to comment.