sphinx-doc / sphinx

The Sphinx documentation generator
https://www.sphinx-doc.org/
Other
6.56k stars 2.12k forks source link

The warning admonition not enforcing line breaks #12881

Open pique-b opened 1 month ago

pique-b commented 1 month ago

Describe the bug

While using admonition warning in my Sphinx doument, I find that a general sentence with a number of words (so as to be longer than the boundary of the admonition to be accommodated) line breaks are enforced once reaching the admonition boundary scope:

An example:

Let's consider the above paragraph itself, the line break has been enforced as we have reached the word/s to be (as in ... (so as to be (may be different for different screen size and resolution!). Actually what I have experienced is that, Sphinx (RestructuredText) goes a step beyond and is able to add line break if it encounters a word that is comprised of a number of letters and applies the line break by breaking up the word.

Whereas if I am to add a longish URL the same effect is not observed (i.e. no line break is applied once the string of texts reaches the admonition's boundary).

Here is an image of what I have described above:

admonition_no_line_brk

As we can see the URL string has travelled beyond the boundary of the admonition.

How to Reproduce

I have used the minimal settings in my conf.py file.

The warning directive as being used is reproduced below:

.. warning::

   #. Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamcoabcdefghijkl laboris nisi ut aliquip

   #. https://www.amazon.com/s?k=high+end+speakers&crid=1N7I9DZEJL9QJ&sprefix=highend+speakers%2Caps%2C522&ref=nb_sb_ss_ts-doa-p_1_16

Environment Information

Sphinx ver 7.2.6
Python 3.9

Sphinx extensions

Only the bare bone that are recommended.

Additional context

So my question is:

jayaddison commented 1 month ago

Further investigation required, but this seems potentially related to: https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_text/Wrapping_breaking_text

pique-b commented 1 month ago

@jayaddison Thanks for sharing the link which was quite informative (and fun too). But to my mind, if Sphinx / reST is able to identify a situation when a particular word might overflow and needed to be broken up, why is it that somehow the long string of URL (as shown above) is not broken up, at the point where it tends to overflow the bounds?

electric-coder commented 1 month ago

why is it that somehow the long string of URL (as shown above) is not broken up

Possibly because the URL gets transformed into an href instead of being standard text and thus has to be targeted with custom CSS that might not be implemented.

pique-b commented 1 month ago

Possibly because the URL gets transformed into an href instead of being standard text

I find that tweaking a file path a litlle also has the effct as described above. In the example below notice how even a little addition gets in the way of correctly(?) rendering the admonition:

The example:

admon_no_lin_brk_2nd

And in the directive:

.. warning::

   WARNING: Notebook exception traceback saved in: 

   /Users/abcdefghijklmnopqrs/Desktop/PY_PY/py_py_vnv/proj_py_dream/build/html/reports/blame_it_on_rio/imageAI.err.log [mystnb.exec]

   WARNING: Notebook exception traceback saved in: 

   /Users/abcdefghijklmnopqrs/abcdefgh/Desktop/PY_PY/py_py_vnv/proj_py_dream/build/html/reports/blame_it_on_rio/imageAI.err.log [mystnb.exec]

Both are essentially the same, except in the second I added a bunch of random letters /abcdefgh just to see how it played out - but again the second example did overflow the bounds.