From c04e8a12201f8e006906bd2379c96562ce8b1a0a Mon Sep 17 00:00:00 2001 From: sudoskys Date: Tue, 22 Oct 2024 01:06:45 +0800 Subject: [PATCH 1/3] =?UTF-8?q?=E2=9C=A8=20feat:=20add=20latex=5Fescape=20?= =?UTF-8?q?parameter=20in=20markdownify=20function?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This update introduces the latex_escape parameter to the markdownify function, allowing customization of LaTeX escaping. --- src/telegramify_markdown/__init__.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/telegramify_markdown/__init__.py b/src/telegramify_markdown/__init__.py index 308e578..7124af7 100644 --- a/src/telegramify_markdown/__init__.py +++ b/src/telegramify_markdown/__init__.py @@ -87,13 +87,16 @@ def _update_block(token: BlockToken): def markdownify( content: str, max_line_length: int = None, - normalize_whitespace=False + normalize_whitespace=False, + latex_escape=None ) -> str: 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) From 3943bd7ca46330636f85597e0b6cd77cf59628a2 Mon Sep 17 00:00:00 2001 From: sudoskys Date: Tue, 22 Oct 2024 01:07:53 +0800 Subject: [PATCH 2/3] :bulb: docs(init): add docstring for markdown conversion function --- src/telegramify_markdown/__init__.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/telegramify_markdown/__init__.py b/src/telegramify_markdown/__init__.py index 7124af7..72c4da1 100644 --- a/src/telegramify_markdown/__init__.py +++ b/src/telegramify_markdown/__init__.py @@ -90,6 +90,14 @@ def markdownify( 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 From c878ee24aef6a1f1691e4ff5e9466f07a5231a23 Mon Sep 17 00:00:00 2001 From: sudoskys Date: Tue, 22 Oct 2024 01:16:11 +0800 Subject: [PATCH 3/3] =?UTF-8?q?=F0=9F=94=A7=20chore(workflow):=20update=20?= =?UTF-8?q?Python=20version=20in=20CI=20to=203.10?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 🔖 chore(release): bump version to 0.1.15 🐛 fix(markdown): improve markdown code formatting logic --- .github/workflows/python_test.yml | 2 +- pyproject.toml | 2 +- src/telegramify_markdown/__init__.py | 3 ++- 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/.github/workflows/python_test.yml b/.github/workflows/python_test.yml index a43b3fa..c0c4d67 100755 --- a/.github/workflows/python_test.yml +++ b/.github/workflows/python_test.yml @@ -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: diff --git a/pyproject.toml b/pyproject.toml index c2e1436..94fdf34 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -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" }, diff --git a/src/telegramify_markdown/__init__.py b/src/telegramify_markdown/__init__.py index 72c4da1..4a03677 100644 --- a/src/telegramify_markdown/__init__.py +++ b/src/telegramify_markdown/__init__.py @@ -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 = []