pdoc3 / pdoc

:snake: :arrow_right: :scroll: Auto-generate API documentation for Python projects
https://pdoc3.github.io/pdoc/
GNU Affero General Public License v3.0
1.13k stars 146 forks source link

Preserve Whitespace? #287

Closed csm10495 closed 3 years ago

csm10495 commented 3 years ago

Is there a flag/setting to preserve Whitespace within multiline docstrings? Right now my multiline docstrings appear to have their newlines lost in translation to html.

Thanks.

kernc commented 3 years ago

HTML doesn't really care about newlines. Currently no provisions to replace '\n' with '<br>' (i.e. line breaks) for HTML output.

Can you show an example docstring that doesn't look right?

csm10495 commented 3 years ago

Sure: https://www.github.com/csm10495/pynom/tree/master/pynom%2Fpynom.py look for the init of PyNom.

Then the docs are here: https://csm10495.github.io/pynom/pynom.html

The newlines weren't preserved in the docstrings which made them look kind of weird compared to the original source code.

kernc commented 3 years ago

Well, there's no indication anywhere in the docs that pdoc should preserve newlines. Pdoc3 supports Numpydoc and Google docstring formats as well as raw Markdown, but no <pre>.

If you care to format your docstrings a little more nicely, following e.g. the Google style guide which results in similar to what you already have, they should render better.

Edit: You can also end your lines with two spaces, which forces Markdown to keep the line break that follows.

Alternatively, you're welcome to edit your html.mako template and wrap docstrings in <pre> tags.