Browse Source

Improved markdown to html conversions (#1089)

pull/1092/head
Chris Caron 8 months ago committed by GitHub
parent
commit
eee2d345d4
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 3
      apprise/conversion.py
  2. 58
      test/test_conversion.py

3
apprise/conversion.py

@ -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):

58
test/test_conversion.py

@ -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…
Cancel
Save