sphinx icon indicating copy to clipboard operation
sphinx copied to clipboard

have backslash be an inline literal word wrap break character in HTML

Open jbaylies opened this issue 1 year ago • 3 comments

Describe the bug

Similar to this issue for latex: https://github.com/sphinx-doc/sphinx/issues/6000

When I view really/long/filepaths on mobile, they are not word wrapped, and just keep going off the side of the page.

How to Reproduce

build a doc that has text with a `really/long/filepath``, open the page on your smartphone, and the path will just keep going off the side of the page.

Environment Information

https://github.com/Sousastep/SousaFX-docs

Sphinx extensions

https://github.com/Sousastep/SousaFX-docs/blob/master/docs/conf.py

jbaylies avatar Jan 08 '24 06:01 jbaylies

my workaround is to put this in custom.css

code {                                 
    white-space: pre-wrap !important; 
    word-break: normal;            
}

and add no-width spaces after the slashes in the file paths.

jbaylies avatar Jan 08 '24 07:01 jbaylies

@jbaylies Can you please provide a concrete test case (or multiple)?

I found the breaking behavior of inline literals (which I think is what you are talking about?) quite brittle.

I have created a test case to test this for my own theme: https://insipid-sphinx-theme.readthedocs.io/en/0.4.2/showcase/basic-formatting.html#inline-markup

My theme uses this CSS:

span.pre {
    white-space: pre-wrap;
    overflow-wrap: anywhere;
}

... while basic.css uses this:

https://github.com/sphinx-doc/sphinx/blob/608335132094ad011f3d06a3db4886f63e71b306/sphinx/themes/basic/static/basic.css_t#L774-L780


It's even worse than I thought, because I just tried it with Chromium and it seems to behave different than Firefox.

Firefox:

image

Chromium:

image

It would be great if we could find a solution that looks the same on both!

mgeier avatar Jan 09 '24 19:01 mgeier

I just looked at the rendered reST page on GitHub: https://github.com/mgeier/insipid-sphinx-theme/blob/master/doc/showcase/basic-formatting.rst

It is also different between Firefox and Chromium!

So maybe (part of) it is a Firefox/Chromium inconsistency?

mgeier avatar Jan 09 '24 20:01 mgeier