mirror of
https://github.com/caronc/apprise.git
synced 2024-11-25 09:33:50 +01:00
Improved markdown to html conversions (#1089)
This commit is contained in:
parent
2c5341a2a5
commit
eee2d345d4
@ -58,8 +58,7 @@ def markdown_to_html(content):
|
|||||||
"""
|
"""
|
||||||
Converts specified content from markdown to HTML.
|
Converts specified content from markdown to HTML.
|
||||||
"""
|
"""
|
||||||
|
return markdown(content, extensions=['nl2br', 'tables'])
|
||||||
return markdown(content)
|
|
||||||
|
|
||||||
|
|
||||||
def text_to_html(content):
|
def text_to_html(content):
|
||||||
|
@ -29,6 +29,7 @@
|
|||||||
from apprise import NotifyFormat
|
from apprise import NotifyFormat
|
||||||
from apprise.conversion import convert_between
|
from apprise.conversion import convert_between
|
||||||
import pytest
|
import pytest
|
||||||
|
from inspect import cleandoc
|
||||||
|
|
||||||
# Disable logging for a cleaner testing output
|
# Disable logging for a cleaner testing output
|
||||||
import logging
|
import logging
|
||||||
@ -150,3 +151,60 @@ def test_conversion_text_to():
|
|||||||
assert response == \
|
assert response == \
|
||||||
'<title>Test Message</title><body>Body<'\
|
'<title>Test Message</title><body>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
|
||||||
|
Loading…
Reference in New Issue
Block a user