diff --git a/yardang/conf.py.j2 b/yardang/conf.py.j2 index fac57902..25a83b90 100644 --- a/yardang/conf.py.j2 +++ b/yardang/conf.py.j2 @@ -411,7 +411,9 @@ def run_convert_github_admonitions_to_rst(app, filename, lines): break else: # replace indent to match directive - if replacing and "> " in line: + if replacing and line == ">": + line = "" + elif replacing and "> " in line: line = line.replace("> ", " ") elif replacing: # missing "> ", so stop replacing and terminate directive diff --git a/yardang/tests/test_sphinx.py b/yardang/tests/test_sphinx.py index 9c36ae6f..d1c19fc2 100644 --- a/yardang/tests/test_sphinx.py +++ b/yardang/tests/test_sphinx.py @@ -1,3 +1,4 @@ +import importlib.util from pathlib import Path from yardang import __version__ @@ -22,3 +23,19 @@ def test_generated_configuration_enables_extension(tmp_path, monkeypatch): conf_content = (Path(conf_dir) / "conf.py").read_text() assert '"yardang.sphinx"' in conf_content + + +def test_github_admonition_preserves_quoted_blank_lines(tmp_path, monkeypatch): + (tmp_path / "pyproject.toml").write_text('[project]\nname = "test-project"\nversion = "1.0.0"\n') + (tmp_path / "README.md").write_text("# Test Project\n") + monkeypatch.chdir(tmp_path) + + with generate_docs_configuration() as conf_dir: + spec = importlib.util.spec_from_file_location("yardang_test_conf", Path(conf_dir) / "conf.py") + conf = importlib.util.module_from_spec(spec) + spec.loader.exec_module(conf) + + lines = ["> [!NOTE]\n> First paragraph.\n>\n> Second paragraph."] + conf.run_convert_github_admonitions_to_rst(None, "index.md", lines) + + assert lines == [":::{note}\n\n First paragraph.\n\n Second paragraph."]