From ab6e17f53e29576e0ea39ace292ad6f4b745d508 Mon Sep 17 00:00:00 2001 From: Ossi Rajuvaara Date: Fri, 1 Sep 2023 16:44:59 +0300 Subject: [PATCH] Ensure code block starts new line --- src/lazydocs/generation.py | 17 +---------------- tests/resources/example/__init__.py | 5 +++++ tests/test_markdown.py | 5 +++++ 3 files changed, 11 insertions(+), 16 deletions(-) diff --git a/src/lazydocs/generation.py b/src/lazydocs/generation.py index 32f9f97..0776260 100755 --- a/src/lazydocs/generation.py +++ b/src/lazydocs/generation.py @@ -305,22 +305,6 @@ def _is_module_ignored(module_name: str, ignored_modules: List[str]) -> bool: return False -def _get_src_root_path(obj: Any) -> str: - """Get the root path to a imported module. - - Args: - obj (Any): Imported python object. - - Returns: - str: Full source root path to the selected object. - """ - module = obj - if not isinstance(obj, types.ModuleType): - module = inspect.getmodule(obj) - root_package = module.__name__.split(".")[0] - return module.__file__.split(root_package)[0] + root_package - - def _get_doc_summary(obj: Any) -> str: # First line should contain the summary return _get_docstring(obj).split("\n")[0] @@ -401,6 +385,7 @@ def _doc2md(obj: Any) -> str: else: md_code_snippet = True snippet_indent = indent + out.append("\n") out.append(line) elif line.strip().endswith("::"): diff --git a/tests/resources/example/__init__.py b/tests/resources/example/__init__.py index d77c1e8..b43f87a 100644 --- a/tests/resources/example/__init__.py +++ b/tests/resources/example/__init__.py @@ -19,6 +19,11 @@ def a_public_function(required: int, optional: Optional[str] = None) -> AClass: This is a second paragraph that should be separate. + This is not an actual header, but has a code-block underneath: + ```python + print("Let's hope this works!") + ``` + Example: ```python from example import a_public_function diff --git a/tests/test_markdown.py b/tests/test_markdown.py index eb9da74..07e6bb1 100644 --- a/tests/test_markdown.py +++ b/tests/test_markdown.py @@ -74,3 +74,8 @@ def test_multiple_paragraphs(markdown): def test_source_link(markdown): assert "_class.py:9" in markdown + + +def test_code_spacing(markdown): + # Ensure no code-blocks are escaped + assert "\\`" not in markdown