Skip to content

Commit 926d7c7

Browse files
committed
Simplify: extract _get_indent method, inline list comprehension
1 parent 08fd1d6 commit 926d7c7

File tree

1 file changed

+10
-10
lines changed

1 file changed

+10
-10
lines changed

markdown_code_runner.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -284,23 +284,23 @@ def _process_start_markers(
284284
return line
285285
return None
286286

287+
@staticmethod
288+
def _get_indent(line: str) -> str:
289+
"""Extract leading whitespace from a line."""
290+
return line[: len(line) - len(line.lstrip())]
291+
287292
def _process_output_start(self, line: str) -> None:
288293
self.section = "output"
289294
if not self.skip_code_block:
290295
assert isinstance(
291296
self.output,
292297
list,
293298
), f"Output must be a list, not {type(self.output)}, line: {line}"
294-
# Extract indent from OUTPUT:START line
295-
output_indent = line[: len(line) - len(line.lstrip())]
296-
297-
def _add_indent(s: str) -> str:
298-
stripped = s.rstrip()
299-
return output_indent + stripped if stripped else ""
300-
301-
trimmed_output = [_add_indent(ol) for ol in self.output]
302-
indented_warning = output_indent + MARKERS["warning"]
303-
self.new_lines.extend([line, indented_warning, *trimmed_output])
299+
indent = self._get_indent(line)
300+
trimmed_output = [
301+
indent + ol.rstrip() if ol.strip() else "" for ol in self.output
302+
]
303+
self.new_lines.extend([line, indent + MARKERS["warning"], *trimmed_output])
304304
else:
305305
self.original_output.append(line)
306306

0 commit comments

Comments
 (0)