Skip to content

Commit

Permalink
enhance lines re-indent on stripping
Browse files Browse the repository at this point in the history
  • Loading branch information
gi0baro committed Apr 20, 2022
1 parent c530021 commit 964149b
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 1 deletion.
6 changes: 5 additions & 1 deletion renoir/parsing/contents.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,10 @@ def __str__(self) -> str:
def __bool__(self) -> bool:
return bool(self.text)

@property
def can_arbitrate_reindent(self) -> bool:
return not bool(str(self))


class ElementSplitted:
__slots__ = ['parent', 'lines']
Expand Down Expand Up @@ -153,7 +157,7 @@ def _has_reindent_arbiter(self):
if prev.idx != self.parent.ctx.strip_arbiter.idx:
prev = prev.prev(2)
else:
rv = True
rv = prev.can_arbitrate_reindent
break
else:
break
Expand Down
10 changes: 10 additions & 0 deletions tests/html/test2.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{{ extend 'layout.html' }}

<ul class="posts">
{{ for post in posts: }}
<li>
<h2>{{ =post['title'] }}</h2>
<hr />
</li>
{{ pass }}
</ul>
42 changes: 42 additions & 0 deletions tests/test_render.py
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,48 @@ def test_html_indent(templater_html_indent):
html_indent_rendered[1:]


html_indent_rendered2 = """
<!DOCTYPE html>
<html>
<head>
<title>Test</title>
</head>
<body>
<div>header1</div>
<div class="page">
<a href="/" class="title"><h1>Test</h1></a>
<div class="nav">
<a href="/">nuvolosit&#224; variabile</a>
</div>
<ul class="posts">
<li>
<h2>foo</h2>
<hr />
</li>
<li>
<h2>bar</h2>
<hr />
</li>
</ul>
</div>
<div>footer</div>
</body>
</html>"""


def test_html_indent2(templater_html_indent):
r = templater_html_indent.render(
'test2.html', {
'posts': [{'title': 'foo'}, {'title': 'bar'}]
}
)
assert "\n".join([l.rstrip() for l in r.splitlines()]) == \
html_indent_rendered2[1:]


html_pre_rendered = """
<div>
<pre>
Expand Down

0 comments on commit 964149b

Please sign in to comment.