Closed xingty closed 3 months ago
This may be a design problem. I may update a major version to solve this problem using dependency injection.
converted = telegramify_markdown.markdownify(
markdown_text,
max_line_length=None, # If you want to change the max line length for links, images, set it to the desired value.
normalize_whitespace=False
)
print(converted)
# export Markdown to Telegram MarkdownV2 style.
Use telegramify_markdown.markdownify instead
Issue Summary:
A user reported that the max_line_length
setting in the telegramify_markdown
module has no effect when updated. The user suspects that this problem arises because the max_line_length
variable is initialized upon importing the render
module.
Test Code Provided: The user provided a test code, which follows the example written in the README, to demonstrate the issue.
from telegramify_markdown import customize
import telegramify_markdown
customize.max_line_length = 256
customize.strict_markdown = True
md = """
[Treating Otitis Externa in Dogs | Today's Veterinary Practice](https://todaysveterinarypractice.com/dermatology/treating-otitis-externa-in-dogs/)
"""
def main():
escaped = telegramify_markdown.convert(md)
print(escaped)
main()
Environment:
Comments and Resolution:
Comment#2205375704 by @sudoskys:
Comment#2208204733 by @sudoskys:
converted = telegramify_markdown.markdownify(
markdown_text,
max_line_length=None, # Set to desired value to change the max line length for links, images.
normalize_whitespace=False
)
print(converted)
telegramify_markdown.markdownify
method instead of convert
.Resolution:
The issue was addressed by providing an alternative method, telegramify_markdown.markdownify
, allowing the user to manually set the max_line_length
parameter.
Flowchart:
graph TD;
A[Issue Reported: max_line_length Setting Ineffective] --> B[Investigate Cause: Initialization on Import]
B --> C[User Suggests Design Problem]
C --> D[Alternative Method Suggested]
D --> E[Resolution: Use telegramify_markdown.markdownify]
Final Status: The issue has been closed by providing the user with an alternative method to achieve the desired functionality.
converted = telegramify_markdown.markdownify( markdown_text, max_line_length=None, # If you want to change the max line length for links, images, set it to the desired value. normalize_whitespace=False ) print(converted) # export Markdown to Telegram MarkdownV2 style.
Use telegramify_markdown.markdownify instead
thanks a lot
I think this is because when we import the
telegramify_markdown
module, it also imports therender
module. As a result, max_line_length is imported and initialized. Therefore, even though we update the value of max_line_length, it will not have any effect.My test code is the same as the example written on README.
env: OS: macOS python: python3.11