sudoskys / telegramify-markdown

🪄 Markdown To Telegram Markdown Converter Python| No more worrying about formatting.
MIT License
47 stars 4 forks source link

max_line_length setting has no effect #15

Closed xingty closed 3 months ago

xingty commented 3 months ago

I think this is because when we import the telegramify_markdown module, it also imports the render 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.

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()

env: OS: macOS python: python3.11

sudoskys commented 3 months ago

This may be a design problem. I may update a major version to solve this problem using dependency injection.

sudoskys commented 3 months ago
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

neutron-nerve[bot] commented 3 months ago

Issue Report: max_line_length Setting Has No Effect

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:

  1. Comment#2205375704 by @sudoskys:

    • Suggested that this might be a design problem and mentioned a potential major update to solve the issue using dependency injection.
  2. Comment#2208204733 by @sudoskys:

    • Provided an alternative solution:
      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)
    • Recommended using the 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.

xingty commented 3 months ago
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