Skip to content

Commit

Permalink
Disable italic markdown rendering
Browse files Browse the repository at this point in the history
  • Loading branch information
yym68686 committed Jul 23, 2024
1 parent 0429bed commit a40cab1
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

setup(
name="md2tgmd",
version="0.2.10",
version="0.3.0",
description="md2tgmd is a Markdown to Telegram-specific-markdown converter.",
long_description=Path("README.md").open(encoding="utf-8").read(),
long_description_content_type="text/markdown",
Expand Down
11 changes: 7 additions & 4 deletions src/md2tgmd.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ def find_lines_with_char(s, char, min_count):

return "\n".join(lines)

def escape(text, flag=0):
def escape(text, flag=0, italic=True):
# In all other places characters
# _ * [ ] ( ) ~ ` > # + - = | { } . !
# must be escaped with the preceding character '\'.
Expand All @@ -130,9 +130,12 @@ def escape(text, flag=0):
if flag:
text = re.sub(r"\@{3}", r"\\\\", text)
# _italic_
text = re.sub(r"\_{1}(.*?)\_{1}", '@@@\\1@@@', text)
text = re.sub(r"_", '\_', text)
text = re.sub(r"\@{3}(.*?)\@{3}", '_\\1_', text)
if italic:
text = re.sub(r"\_{1}(.*?)\_{1}", '@@@\\1@@@', text)
text = re.sub(r"_", '\_', text)
text = re.sub(r"\@{3}(.*?)\@{3}", '_\\1_', text)
else:
text = re.sub(r"_", '\_', text)

text = re.sub(r"\*{2}(.*?)\*{2}", '@@@\\1@@@', text)
text = re.sub(r"\n{1,2}\*\s", '\n\n• ', text)
Expand Down

0 comments on commit a40cab1

Please sign in to comment.