Skip to content

Commit

Permalink
fix: Don't render anything when code block output is empty
Browse files Browse the repository at this point in the history
By empty, we mean absolutely empty. A single blank character will be (converted and) rendered.

Issue-17: #17
  • Loading branch information
pawamoy committed Jun 12, 2024
1 parent 93598b2 commit 4337d13
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/markdown_exec/formatters/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,9 @@ def base_format(
logger.warning(log_message)
return markdown.convert(str(error))

if not output:
return Markup()

if html:
if source:
placeholder = str(uuid4())
Expand Down
15 changes: 15 additions & 0 deletions tests/test_base_formatter.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,3 +58,18 @@ def test_render_console_plus_ansi_result(md: Markdown) -> None:
result="ansi",
)
assert "<code>ansi" in markup


def test_dont_render_anything_if_output_is_empty(md: Markdown) -> None:
"""Assert nothing is rendered if output is empty.
Parameters:
md: A Markdown instance (fixture).
"""
markup = base_format(
language="bash",
run=lambda code, **_: "",
code="whatever",
md=md,
)
assert not markup

0 comments on commit 4337d13

Please # to comment.