Skip to content

remove superfluous leading/trailing whitespace #181

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jan 27, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
change default to strip_document=STRIP, move unit-testing md() to com…
…mon test utils file

Signed-off-by: chrispy <[email protected]>
  • Loading branch information
chrispy-snps committed Jan 27, 2025
commit 1586f9834fdb6176c79c436b205c9816757502db
4 changes: 2 additions & 2 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -153,9 +153,9 @@ wrap, wrap_width
strip_document
Controls whether leading and/or trailing separation newlines are removed from
the final converted document. Supported values are ``LSTRIP`` (leading),
``RSTRIP`` (trailing), ``STRIP`` (both), and ``None`` (no removal). Newlines
``RSTRIP`` (trailing), ``STRIP`` (both), and ``None`` (neither). Newlines
within the document are unaffected.
Defaults to ``LSTRIP``.
Defaults to ``STRIP``.

Options may be specified as kwargs to the ``markdownify`` function, or as a
nested ``Options`` class in ``MarkdownConverter`` subclasses.
Expand Down
2 changes: 1 addition & 1 deletion markdownify/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ class DefaultOptions:
keep_inline_images_in = []
newline_style = SPACES
strip = None
strip_document = LSTRIP
strip_document = STRIP
strong_em_symbol = ASTERISK
sub_symbol = ''
sup_symbol = ''
Expand Down
9 changes: 1 addition & 8 deletions tests/test_advanced.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,4 @@
from markdownify import MarkdownConverter


def md(html, **options):
# disable document-level stripping so separation newlines are included in testing
options = {**options, "strip_document": None}

return MarkdownConverter(**options).convert(html)
from .utils import md


def test_chomp():
Expand Down
13 changes: 7 additions & 6 deletions tests/test_args.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
Test whitelisting/blacklisting of specific tags.

"""
from markdownify import markdownify as md, LSTRIP, RSTRIP, STRIP
from markdownify import markdownify, LSTRIP, RSTRIP, STRIP
from .utils import md


def test_strip():
Expand All @@ -26,8 +27,8 @@ def test_do_not_convert():


def test_strip_document():
assert md("<p>Hello</p>") == "Hello\n\n" # defaults to LSTRIP
assert md("<p>Hello</p>", strip_document=LSTRIP) == "Hello\n\n"
assert md("<p>Hello</p>", strip_document=RSTRIP) == "\n\nHello"
assert md("<p>Hello</p>", strip_document=STRIP) == "Hello"
assert md("<p>Hello</p>", strip_document=None) == "\n\nHello\n\n"
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"
9 changes: 1 addition & 8 deletions tests/test_basic.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,4 @@
from markdownify import MarkdownConverter


def md(html, **options):
# disable document-level stripping so separation newlines are included in testing
options = {**options, "strip_document": None}

return MarkdownConverter(**options).convert(html)
from .utils import md


def test_single_tag():
Expand Down
10 changes: 2 additions & 8 deletions tests/test_conversions.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,5 @@
from markdownify import MarkdownConverter, ATX, ATX_CLOSED, BACKSLASH, SPACES, UNDERSCORE


def md(html, **options):
# disable document-level stripping so separation newlines are included in testing
options = {**options, "strip_document": None}

return MarkdownConverter(**options).convert(html)
from markdownify import ATX, ATX_CLOSED, BACKSLASH, SPACES, UNDERSCORE
from .utils import md


def inline_tests(tag, markup):
Expand Down
4 changes: 2 additions & 2 deletions tests/test_custom_converter.py
Original file line number Diff line number Diff line change
Expand Up @@ -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" />') == '![Alt text](/path/to/img.jpg "Optional title")\n\n'
assert md('<img src="/path/to/img.jpg" alt="Alt text" />') == '![Alt text](/path/to/img.jpg)\n\n'
assert md('<img src="/path/to/img.jpg" alt="Alt text" title="Optional title" />text') == '![Alt text](/path/to/img.jpg "Optional title")\n\ntext'
assert md('<img src="/path/to/img.jpg" alt="Alt text" />text') == '![Alt text](/path/to/img.jpg)\n\ntext'

assert md("<custom-tag>text</custom-tag>") == "FUNCTION USED: text"

Expand Down
9 changes: 1 addition & 8 deletions tests/test_escaping.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,6 @@
import warnings
from bs4 import MarkupResemblesLocatorWarning
from markdownify import MarkdownConverter


def md(html, **options):
# disable document-level stripping so separation newlines are included in testing
options = {**options, "strip_document": None}

return MarkdownConverter(**options).convert(html)
from .utils import md


def test_asterisks():
Expand Down
9 changes: 1 addition & 8 deletions tests/test_lists.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,4 @@
from markdownify import MarkdownConverter


def md(html, **options):
# disable document-level stripping so separation newlines are included in testing
options = {**options, "strip_document": None}

return MarkdownConverter(**options).convert(html)
from .utils import md


nested_uls = """
Expand Down
9 changes: 1 addition & 8 deletions tests/test_tables.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,4 @@
from markdownify import MarkdownConverter


def md(html, **options):
# disable document-level stripping so separation newlines are included in testing
options = {**options, "strip_document": None}

return MarkdownConverter(**options).convert(html)
from .utils import md


table = """<table>
Expand Down
9 changes: 9 additions & 0 deletions tests/utils.py
Original file line number Diff line number Diff line change
@@ -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)
Loading