# -*- coding: utf-8 -*-
# BSD 2-Clause License
#
# Apprise - Push Notification Library.
# Copyright (c) 2025, Chris Caron And a paragraph too. Some obnoxious text here. line 1 line 2 line 3 line 1 line 2 line 3 line 1>"
" line 2"
" line 3>") == "line 1\nline 2\nline 3>"
# Make sure we ignore fields that aren't important to us
assert to_html(
""
" line 1
")
assert "Lots and lots" in clist
assert "of lists." in clist
assert "To be or not to be." in to_html(
"To be or not to be.
")
cspace = to_html(
"Fancy heading
"
"
Plus line break.
and )
assert to_html(
"some information
and more information") == \
"some information\n\nand more information"
#
# Test bad tags
#
# first 2 entries are okay, but last will do as best as it can
assert to_html(
"
3rd line") == \ "line 1 bold\nmy link\n3rd line" #
FROM: apprise-test@mydomain.yyy
FROM: apprise-test@mydomain.yyy
To be or not to be.") cspace = to_markdown( "
And a paragraph too.
Plus line break.
Some obnoxious text here.
") == "Some obnoxious text here." assert to_markdown( "line 1
" "line 2
" "line 3
") == "line 1\nline 2\nline 3" # Case sensitivity assert to_markdown( "line 1
" "line 2
" "line 3
") == "line 1\nline 2\nline 3" # double new lines (testingline 1>" "
line 2" "
line 3>") == \ "# Heading 1\n## Heading 2\n### Heading 3\n" \ "#### Heading 4\n##### Heading 5\n###### Heading 6\n" \ "line 1\n*line 2*\nline 3>" # Make sure we ignore fields that aren't important to us assert to_markdown( "" "
line 1
" "Another line without being enclosed") == \ "line 1\nAnother line without being enclosed" # Test and
assert to_markdown(
"multi-line 1\nmulti-line 2
more content"
"multi-line 1\nmulti-line 2
more content") == \
'`multi-line 1\nmulti-line 2`more content' \
'\n```\nmulti-line 1\nmulti-line 2\n```\nmore content'
# Test cases when there are no new lines (we're dealing with just inline
# entries); an empty entry as well
assert to_markdown("test "
"my link") == \
"test [my link](#)"
# missing
assert to_markdown("line 1 bold "
" my link"
"3rd line") == \
"line 1 **bold**\n[my link](/link)\n3rd line"
#
on it's own
assert to_markdown("
") == "---"
assert to_markdown("
") == "---"
# We need to handle HTML Encodings
assert to_markdown("""
ignore this entry
Let's handle special html encoding
""") == "Let's handle special html encoding\n---"
# If you give nothing, you get nothing in return
assert to_markdown("") == ""
with pytest.raises(TypeError):
# Invalid input
assert to_markdown(None)
with pytest.raises(TypeError):
# Invalid input
assert to_markdown(42)
with pytest.raises(TypeError):
# Invalid input
assert to_markdown(object)
def test_conversion_text_to():
"""conversion: Test Text to all types
"""
response = convert_between(
NotifyFormat.TEXT, NotifyFormat.HTML,
"Test Message Body")
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 '
Foo ' in response
assert 'Bar ' in response
assert 'Some Heading
' in response
assert '
' 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 '
' 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 '' in response
assert 'First Header ' in response
assert 'Second Header ' in response
assert 'Content Cell1 ' in response
assert 'Content Cell2 ' in response
assert 'Content Cell3 ' in response
assert 'Content Cell4 ' in response