remove superfluous leading/trailing whitespace (#181)
This commit is contained in:
committed by
GitHub
parent
dbb5988802
commit
ae0597d80c
@@ -1,4 +1,4 @@
|
||||
from markdownify import markdownify as md
|
||||
from .utils import md
|
||||
|
||||
|
||||
def test_chomp():
|
||||
|
||||
@@ -2,7 +2,8 @@
|
||||
Test whitelisting/blacklisting of specific tags.
|
||||
|
||||
"""
|
||||
from markdownify import markdownify as md
|
||||
from markdownify import markdownify, LSTRIP, RSTRIP, STRIP
|
||||
from .utils import md
|
||||
|
||||
|
||||
def test_strip():
|
||||
@@ -23,3 +24,11 @@ def test_convert():
|
||||
def test_do_not_convert():
|
||||
text = md('<a href="https://github.com/matthewwithanm">Some Text</a>', convert=[])
|
||||
assert text == 'Some Text'
|
||||
|
||||
|
||||
def test_strip_document():
|
||||
assert markdownify("<p>Hello</p>") == "Hello" # test default of STRIP
|
||||
assert markdownify("<p>Hello</p>", strip_document=LSTRIP) == "Hello\n\n"
|
||||
assert markdownify("<p>Hello</p>", strip_document=RSTRIP) == "\n\nHello"
|
||||
assert markdownify("<p>Hello</p>", strip_document=STRIP) == "Hello"
|
||||
assert markdownify("<p>Hello</p>", strip_document=None) == "\n\nHello\n\n"
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
from markdownify import markdownify as md
|
||||
from .utils import md
|
||||
|
||||
|
||||
def test_single_tag():
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
from markdownify import markdownify as md, ATX, ATX_CLOSED, BACKSLASH, SPACES, UNDERSCORE
|
||||
from markdownify import ATX, ATX_CLOSED, BACKSLASH, SPACES, UNDERSCORE
|
||||
from .utils import md
|
||||
|
||||
|
||||
def inline_tests(tag, markup):
|
||||
@@ -79,11 +80,6 @@ def test_br():
|
||||
assert md('a<br />b<br />c', newline_style=BACKSLASH) == 'a\\\nb\\\nc'
|
||||
|
||||
|
||||
def test_caption():
|
||||
assert md('TEXT<figure><figcaption>Caption</figcaption><span>SPAN</span></figure>') == 'TEXT\n\nCaption\n\nSPAN'
|
||||
assert md('<figure><span>SPAN</span><figcaption>Caption</figcaption></figure>TEXT') == 'SPAN\n\nCaption\n\nTEXT'
|
||||
|
||||
|
||||
def test_code():
|
||||
inline_tests('code', '`')
|
||||
assert md('<code>*this_should_not_escape*</code>') == '`*this_should_not_escape*`'
|
||||
@@ -126,6 +122,11 @@ def test_em():
|
||||
inline_tests('em', '*')
|
||||
|
||||
|
||||
def test_figcaption():
|
||||
assert (md("TEXT<figure><figcaption>\nCaption\n</figcaption><span>SPAN</span></figure>") == "TEXT\n\nCaption\n\nSPAN")
|
||||
assert (md("<figure><span>SPAN</span><figcaption>\nCaption\n</figcaption></figure>TEXT") == "SPAN\n\nCaption\n\nTEXT")
|
||||
|
||||
|
||||
def test_header_with_space():
|
||||
assert md('<h3>\n\nHello</h3>') == '\n\n### Hello\n\n'
|
||||
assert md('<h3>Hello\n\n\nWorld</h3>') == '\n\n### Hello World\n\n'
|
||||
@@ -236,6 +237,7 @@ def test_kbd():
|
||||
|
||||
def test_p():
|
||||
assert md('<p>hello</p>') == '\n\nhello\n\n'
|
||||
assert md("<p><p>hello</p></p>") == "\n\nhello\n\n"
|
||||
assert md('<p>123456789 123456789</p>') == '\n\n123456789 123456789\n\n'
|
||||
assert md('<p>123456789\n\n\n123456789</p>') == '\n\n123456789\n123456789\n\n'
|
||||
assert md('<p>123456789\n\n\n123456789</p>', wrap=True, wrap_width=80) == '\n\n123456789 123456789\n\n'
|
||||
|
||||
@@ -20,8 +20,8 @@ def test_custom_conversion_functions():
|
||||
def md(html, **options):
|
||||
return UnitTestConverter(**options).convert(html)
|
||||
|
||||
assert md('<img src="/path/to/img.jpg" alt="Alt text" title="Optional title" />') == '\n\n'
|
||||
assert md('<img src="/path/to/img.jpg" alt="Alt text" />') == '\n\n'
|
||||
assert md('<img src="/path/to/img.jpg" alt="Alt text" title="Optional title" />text') == '\n\ntext'
|
||||
assert md('<img src="/path/to/img.jpg" alt="Alt text" />text') == '\n\ntext'
|
||||
|
||||
assert md("<custom-tag>text</custom-tag>") == "FUNCTION USED: text"
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import warnings
|
||||
from bs4 import MarkupResemblesLocatorWarning
|
||||
from markdownify import markdownify as md
|
||||
from .utils import md
|
||||
|
||||
|
||||
def test_asterisks():
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
from markdownify import markdownify as md
|
||||
from .utils import md
|
||||
|
||||
|
||||
nested_uls = """
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
from markdownify import markdownify as md
|
||||
from .utils import md
|
||||
|
||||
|
||||
table = """<table>
|
||||
@@ -228,7 +228,10 @@ table_body = """<table>
|
||||
</tbody>
|
||||
</table>"""
|
||||
|
||||
table_with_caption = """TEXT<table><caption>Caption</caption>
|
||||
table_with_caption = """TEXT<table>
|
||||
<caption>
|
||||
Caption
|
||||
</caption>
|
||||
<tbody><tr><td>Firstname</td>
|
||||
<td>Lastname</td>
|
||||
<td>Age</td>
|
||||
|
||||
9
tests/utils.py
Normal file
9
tests/utils.py
Normal file
@@ -0,0 +1,9 @@
|
||||
from markdownify import MarkdownConverter
|
||||
|
||||
|
||||
# for unit testing, disable document-level stripping by default so that
|
||||
# separation newlines are included in testing
|
||||
def md(html, **options):
|
||||
options = {"strip_document": None, **options}
|
||||
|
||||
return MarkdownConverter(**options).convert(html)
|
||||
Reference in New Issue
Block a user