Main TitleTM
Abstract
a b c
Premise
a space
nospace
This isa link.
diff --git a/htmlmin/minify.py b/htmlmin/minify.py index f3b0a7b..eb34378 100644 --- a/htmlmin/minify.py +++ b/htmlmin/minify.py @@ -175,23 +175,19 @@ def is_cond_comment(soup): def is_inflow(soup): - """test whether an element belongs to a text flow, returns a tuple + """Test whether a NavigableString belongs to a text flow, returns a tuple of two booleans describing the flow around the element. The first boolean represents the flow before the element, the second boolean represents the flow after the element. - :param soup: a BeautifulSoup of the code to reduce - :type soup: bs4.BeautifulSoup + :param soup: a NavigableString of the code to reduce + :type soup: bs4.element.NavigableString """ - if soup.previous_sibling is not None and \ - soup.previous_sibling.name in TEXT_FLOW: - prev_flow = True - else: - prev_flow = False - if soup.next_sibling is not None and \ - soup.next_sibling.name in TEXT_FLOW: - next_flow = True - else: - next_flow = False - - return (prev_flow, next_flow) + def is_text_tag(soup): + return soup and soup.name in TEXT_FLOW + + if is_text_tag(soup.parent): + # NavigableString is within a text tag element + return (True, True) + + return (is_text_tag(soup.previous_sibling), is_text_tag(soup.next_sibling)) diff --git a/htmlmin/tests/resources/inline_whitespace_minified.html b/htmlmin/tests/resources/inline_whitespace_minified.html index 24a24e5..c20d7fc 100644 --- a/htmlmin/tests/resources/inline_whitespace_minified.html +++ b/htmlmin/tests/resources/inline_whitespace_minified.html @@ -1 +1 @@ -
a b c
a space
nospace
This isa link.
a b c
a space
no space
This is a link.
a b
+c d
+e f
+g h
+i j
+k l
+m n
+o p
+q r
+s t
+u v
+w x
+y
+ z
a b
' + 'c d
' + 'e f
' + 'g h
' + 'i j
' + 'k l
' + 'm n
' + 'o p
' + 'q r
' + 's t
' + 'u v
' + 'w x
' + 'y
' + ' z