Improved markdown to html conversions (#1089)

This commit is contained in:
Chris Caron 2024-03-29 21:49:53 -04:00 committed by GitHub
parent 2c5341a2a5
commit eee2d345d4
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 59 additions and 2 deletions

View File

@ -58,8 +58,7 @@ def markdown_to_html(content):
"""
Converts specified content from markdown to HTML.
"""
return markdown(content)
return markdown(content, extensions=['nl2br', 'tables'])
def text_to_html(content):

View File

@ -29,6 +29,7 @@
from apprise import NotifyFormat
from apprise.conversion import convert_between
import pytest
from inspect import cleandoc
# Disable logging for a cleaner testing output
import logging
@ -150,3 +151,60 @@ def test_conversion_text_to():
assert response == \
'<title>Test Message</title><body>Body<'\
'/body>'
def test_conversion_markdown_to_html():
"""conversion: Test markdown to html
"""
# While this uses the underlining markdown library
# what we're testing for are the edge cases we know it doesn't support
# hence, `-` (a dash) with the markdown library must be a `*` to work
# correctly
response = convert_between(
NotifyFormat.MARKDOWN, NotifyFormat.HTML, cleandoc("""
## Some Heading
With Data:
- Foo
- Bar
"""))
assert '<li>Foo</li>' in response
assert '<li>Bar</li>' in response
assert '<h2>Some Heading</h2>' in response
assert '<br />' not in response
# if the - follows With Data on the very next line, it's consider to not
# requiring indentation
response = convert_between(
NotifyFormat.MARKDOWN, NotifyFormat.HTML, cleandoc("""
## Some Heading
With Data:
- Foo
- Bar
"""))
# Breaks are added:
assert '<br />' in response
assert '- Foo' in response
assert '- Bar' in response
# Table formatting
response = convert_between(
NotifyFormat.MARKDOWN, NotifyFormat.HTML, cleandoc("""
First Header | Second Header
-------------- | -------------
Content Cell1 | Content Cell3
Content Cell2 | Content Cell4
"""))
assert '<table>' in response
assert '<th>First Header</th>' in response
assert '<th>Second Header</th>' in response
assert '<td>Content Cell1</td>' in response
assert '<td>Content Cell2</td>' in response
assert '<td>Content Cell3</td>' in response
assert '<td>Content Cell4</td>' in response