sphinx_rtd_theme icon indicating copy to clipboard operation
sphinx_rtd_theme copied to clipboard

Autodoc generated documentation overflow for python classes with a long import path

Open federicodabrunzo opened this issue 1 year ago • 2 comments

Problem

The documentation generated with the autoclass directive for python classes placed in a module with a long import path overflows the wy-nav-content div.

Reproducible Project

https://github.com/federicodabrunzo/render-issue-for-autodoc-generated-class-with-long-import-path/tree/main?tab=readme-ov-file

Error Logs/Results

image

Expected Results

The <dt> element containing the class import path should not overflow its containing elements.

Environment Info

  • Python Version: 3.11.9
  • Sphinx Version: 8.1.3
  • RTD Theme Version: 3.0.1

federicodabrunzo avatar Nov 19 '24 14:11 federicodabrunzo

To fix just on your specific project, you could put the following line in your custom CSS. See the image at the end of this StackOverflow answer for the effect (look at "SomeLongModule.SomeLongClassName"). It breaks long identifiers (or any long word) but only if strictly necessary to fit everything within the width.

html.writer-html5 .rst-content { overflow-wrap: break-word }

This is not to say that this bug report is invalid. IMO, the theme should include that styling by default.

A disadvantage of this approach is that the break can be anywhere in the identifier, whereas maybe it would be better to only break next to a dot (i.e. "foo.bar" becomes "foo.\nbar"). I don't think that can be done in CSS though so it would need a change in document generation in sphinx itself rather than in the theme (to insert <wbr> elements next to dots). But I actually quite like that the above CSS works even with long identifier fragments and non-identifier words.

arthur-tacca avatar Nov 23 '24 10:11 arthur-tacca

@arthur-tacca Thanks for reporting this — it works fine for my usecase :)

IMO, the theme should include that styling by default.

I agree with that.

federicodabrunzo avatar Dec 17 '24 11:12 federicodabrunzo