Skip to content

Commit

Permalink
Fix the bug where the hyphen is completely replaced during markdown r…
Browse files Browse the repository at this point in the history
…endering.
  • Loading branch information
yym68686 committed May 27, 2024
1 parent 80d7a6b commit d40e66a
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 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.0",
version="0.2.1",
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
8 changes: 4 additions & 4 deletions src/md2tgmd.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ def escapeminus(text):
return '\\' + text

def escapeminus2(text):
return r'@->@'
return r'@+>@'

def escapebackquote(text):
return r'\`\`'
Expand Down Expand Up @@ -107,11 +107,11 @@ def escape(text, flag=0):
text = re.sub(r"\n{1,2}(\s*\d{1,2}\.\s)", '\n\n\\1', text)
# # 把 code block 以外的 - 替换掉
text = replace_all(text, r"```[\D\d\s]+?```|(-)", escapeminus2)
text = re.sub(r"-", '@<-@', text)
text = re.sub(r"\@\-\>\@", '-', text)
text = re.sub(r"-", '@<+@', text)
text = re.sub(r"\@\+\>\@", '-', text)

text = re.sub(r"\n{1,2}(\s*)-\s", '\n\n\\1• ', text)
text = re.sub(r"\@\<\-\@", '\-', text)
text = re.sub(r"\@\<\+\@", '\-', text)
text = replace_all(text, r"(-)|\n[\s]*-\s|```[\D\d\s]+?```|`[\D\d\s]*?`", escapeminus)
text = re.sub(r"```([\D\d\s]+?)```", '@@@\\1@@@', text)
# 把 code block 里面的`替换掉
Expand Down

0 comments on commit d40e66a

Please sign in to comment.