diff --git a/src/markdown_exec/formatters/base.py b/src/markdown_exec/formatters/base.py index 03e07a0..ab37b39 100644 --- a/src/markdown_exec/formatters/base.py +++ b/src/markdown_exec/formatters/base.py @@ -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()) diff --git a/tests/test_base_formatter.py b/tests/test_base_formatter.py index ba439cf..521b5d8 100644 --- a/tests/test_base_formatter.py +++ b/tests/test_base_formatter.py @@ -58,3 +58,18 @@ def test_render_console_plus_ansi_result(md: Markdown) -> None: result="ansi", ) assert "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