Skip to content

Commit 103e928

Browse files
Keep indentation separate for pre-post tag
1 parent e3bd2e3 commit 103e928

File tree

1 file changed

+8
-7
lines changed

1 file changed

+8
-7
lines changed

pyhtml/__tag_base.py

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -155,10 +155,13 @@ def _render(
155155
)
156156
)
157157

158-
indent_str = "" if skip_indent else indent
158+
# Indentation to use before opening tag
159+
indent_pre = "" if skip_indent else indent
160+
# Indentation to use before closing tag
161+
indent_post = "" if skip_indent or options.indent is None else indent
159162

160163
# Tag and attributes
161-
opening = f"{indent_str}<{self._get_tag_name()}"
164+
opening = f"{indent_pre}<{self._get_tag_name()}"
162165

163166
# Add pre-content
164167
if (pre := self._get_tag_pre_content()) is not None:
@@ -178,17 +181,15 @@ def _render(
178181
children = util.render_children(
179182
self.children,
180183
self._escape_children(),
181-
""
182-
if indent_increase is None
183-
else indent + indent_increase,
184+
"" if indent_increase is None else indent + indent_increase,
184185
options,
185186
)
186187
closing = f"</{self._get_tag_name()}>"
187188
if options.spacing == "\n":
188189
return [
189190
opening,
190191
*children,
191-
f"{indent_str}{closing}",
192+
f"{indent_post}{closing}",
192193
]
193194
else:
194195
# Children must have at least one line, since we would have
@@ -201,7 +202,7 @@ def _render(
201202
# Add the closing tag onto the end
202203
return [
203204
*out[:-1],
204-
indent_str + out[-1] + options.spacing + closing,
205+
indent_post + out[-1] + options.spacing + closing,
205206
]
206207

207208
def render(self) -> str:

0 commit comments

Comments
 (0)