diff --git a/src/markdown_exec/__init__.py b/src/markdown_exec/__init__.py index 9ffaf14..f8e6a0a 100644 --- a/src/markdown_exec/__init__.py +++ b/src/markdown_exec/__init__.py @@ -72,7 +72,7 @@ def validator( id_prefix_value = inputs.pop("idprefix", None) html_value = _to_bool(inputs.pop("html", "no")) source_value = inputs.pop("source", "") - result_value = inputs.pop("result", "") + result_value = inputs.pop("result", None) returncode_value = int(inputs.pop("returncode", "0")) session_value = inputs.pop("session", "") update_toc_value = _to_bool(inputs.pop("updatetoc", "yes")) diff --git a/src/markdown_exec/formatters/base.py b/src/markdown_exec/formatters/base.py index 10fbc41..121cb33 100644 --- a/src/markdown_exec/formatters/base.py +++ b/src/markdown_exec/formatters/base.py @@ -92,7 +92,7 @@ def base_format( md: Markdown, html: bool = False, source: str = "", - result: str = "", + result: str = None, tabs: tuple[str, str] = default_tabs, id: str = "", # noqa: A002 id_prefix: str | None = None, @@ -172,7 +172,7 @@ def base_format( return Markup(output) wrapped_output = output - if result and source != "console": + if result is not None and source != "console": wrapped_output = code_block(result, output) if source: wrapped_output = add_source( diff --git a/tests/test_base_formatter.py b/tests/test_base_formatter.py index d1679b6..0904a1e 100644 --- a/tests/test_base_formatter.py +++ b/tests/test_base_formatter.py @@ -127,3 +127,19 @@ def test_console_width(md: Markdown) -> None: width=width, ) assert f"width: {width}" in markup + + +def test_render_as_code_for_empty_string(md: Markdown) -> None: + """Assert backticks are added for empty string + + Parameters: + md: A Markdown instance (fixture). + """ + markup = base_format( + language="python", + run=lambda code, **_: code, + code="print('hello')", + result="", + md=md, + ) + assert "" in markup