Skip to content

Commit

Permalink
Merge pull request #31 from sudoskys/dev
Browse files Browse the repository at this point in the history
fix(bug):Python310, patch 0.1.14
  • Loading branch information
sudoskys authored Oct 21, 2024
2 parents 0229382 + c878ee2 commit 8037c20
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 5 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/python_test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:
runs-on: ${{ matrix.os }}
strategy:
matrix:
python-version: [ '3.12' ] # DO NOT disturb telegram server...
python-version: [ '3.10' ] # DO NOT disturb telegram server...
os: [ ubuntu-latest ] #, windows-latest ] #, macos-latest

steps:
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[project]
name = "telegramify-markdown"
version = "0.1.14"
version = "0.1.15"
description = "Convert Markdown to a format usable by Telegram."
authors = [
{ name = "sudoskys", email = "coldlando@hotmail.com" },
Expand Down
18 changes: 15 additions & 3 deletions src/telegramify_markdown/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@ def latex2unicode(match, is_block):
if is_block:
return f"```{content.strip()}```"
else:
return f"`{content.strip().strip('\n')}`"
pre_process = content.strip().strip('\n')
return f"`{pre_process}`"

lines = text.split("\n\n")
processed_lines = []
Expand Down Expand Up @@ -87,13 +88,24 @@ def _update_block(token: BlockToken):
def markdownify(
content: str,
max_line_length: int = None,
normalize_whitespace=False
normalize_whitespace=False,
latex_escape=None
) -> str:
"""
Convert markdown content to Telegram markdown format.
:param content: The markdown content to convert.
:param max_line_length: The maximum length of a line.
:param normalize_whitespace: Whether to normalize whitespace.
:param latex_escape: Whether to make LaTeX content readable in Telegram.
:return: The Telegram markdown formatted content. **Need Send in MarkdownV2 Mode.**
"""
with TelegramMarkdownRenderer(
max_line_length=max_line_length,
normalize_whitespace=normalize_whitespace
) as renderer:
if customize.latex_escape:
if latex_escape is None:
latex_escape = customize.latex_escape
if latex_escape:
content = escape_latex(content)
document = mistletoe.Document(content)
_update_block(document)
Expand Down

0 comments on commit 8037c20

Please sign in to comment.