To preserve line breaks in Sphinx-generated documentation from Python docstrings, you can format your docstrings using reStructuredText (reST) syntax properly. Sphinx uses reST as the markup language, and for it to respect the line breaks and formatting, you need to adhere to certain conventions.
Here’s how you can modify your docstring:
Arguments
, Returns
, etc.Here’s an updated version of your docstring:
Arguments
With napoleon
, you can write your docstring in a clearer format:
def testMethod(arg1, arg2): """ This is a test method. Args: arg1: arg1 description arg2: arg2 description Returns: None """ print("I am a test method")
napoleon
extension to simplify docstring formatting.By following these steps, Sphinx will preserve the line breaks and generate the documentation with the correct structure.