From fbfb2a7906254b9e3e41c88db425a98314ce4404 Mon Sep 17 00:00:00 2001 From: Zsolt Dollenstein Date: Sat, 1 Jun 2024 22:51:32 +0100 Subject: [PATCH] Treat Python console snippets as rst Docstrings that have console snippets embedded like: ``` """ Return the argument. >>> o = object() """ ``` Render much nicer if parsed as RST. --- py_wtf/indexer/documentation.py | 1 + tests/indexer/test_documentation.py | 7 +++++++ 2 files changed, 8 insertions(+) diff --git a/py_wtf/indexer/documentation.py b/py_wtf/indexer/documentation.py index fe7c3662e..88bf6ac06 100644 --- a/py_wtf/indexer/documentation.py +++ b/py_wtf/indexer/documentation.py @@ -16,6 +16,7 @@ r"|(::\n)" # literal blocks r"|((^|\n)\.\. )" # definitions r"|([^`]``[^`]+``[^`])" # inline literal + r"|((^|\n)>>> )" # python console snippet ) diff --git a/tests/indexer/test_documentation.py b/tests/indexer/test_documentation.py index ae8ef3cc7..7389f8661 100644 --- a/tests/indexer/test_documentation.py +++ b/tests/indexer/test_documentation.py @@ -37,6 +37,13 @@ def test_is_rst() -> None: """ ) assert is_rst("hello\n.. foo:\nbar") + assert is_rst(">>> 1+1") + assert is_rst( + """foo bar +>>> print(1) +1 +""" + ) def test_description_content_type_md() -> None: