long lines in code blocks

1,662 views
Skip to first unread message

elaine

unread,
Sep 15, 2009, 8:22:45 AM9/15/09
to sphinx-dev
hi there --

i think what i have is a reST question and am hoping for a reST or
sphinx solution:

lines of regular text in reST wrap automatically. however, if i have
a very long line in a code block, it does not wrap automatically (e.g.
results in a scroll bar in an html representation, or is simply cut
off the page in the pdf build of a latex representation). is there a
quick fix for this, or do i have to format this by hand?

thanks very much!

elaine

Roberto Alsina

unread,
Sep 15, 2009, 8:27:01 AM9/15/09
to sphin...@googlegroups.com

There is no possible "correct" solution for this.

Since it's code, it can't be automatically wrapped, because it breaks[1].

In rst2pdf I offer a "shrink" fit where the font size is decreased until it
fits the page, but it's not meant for production usage (you can end with
completely unreadable blocks!)

So, I expect the answer is "yes, you need to format it by hand".

And the really bad news: you probably need to format it by hand again for
printing, if you want to print.

[1] Ok, if you know the language you *could* wrap it in some cases. But in
arbitrary code blocks you don't.

--
("\''/").__..-''"`-. . Roberto Alsina
`9_ 9 ) `-. ( ).`-._.`) KDE Developer (MFCH)
(_Y_.)' ._ ) `._`. " -.-' http://lateral.netmanagers.com.ar
_..`-'_..-_/ /-'_.' The 6,855th most popular site of Slovenia
(l)-'' ((i).' ((!.' according to alexa.com (27/5/2007)

Elaine Angelino

unread,
Sep 15, 2009, 8:41:16 AM9/15/09
to sphin...@googlegroups.com
ahh that is a good point!  no quick fix in general...

Elaine Angelino

unread,
Sep 15, 2009, 9:06:49 AM9/15/09
to sphin...@googlegroups.com
wait -- for the html build, no parsing is necessary, it would just be a matter of soft-wrapping the lines of code instead of using a scroll bar for a code block.  is this possible?

(this obviously doesn't solve the problem for pdf latex)

Roberto Alsina

unread,
Sep 15, 2009, 9:12:24 AM9/15/09
to sphin...@googlegroups.com
On Tuesday 15 September 2009 10:06:49 Elaine Angelino wrote:
> wait -- for the html build, no parsing is necessary, it would just be a
> matter of soft-wrapping the lines of code instead of using a scroll bar for
> a code block. is this possible?

It's just a matter of CSS. Probably you want to use something like pre-wrap
and overflow-visible.

http://www.w3schools.com/Css/pr_pos_overflow.asp
http://www.w3schools.com/CSS/pr_text_white-space.asp

Elaine Angelino

unread,
Sep 15, 2009, 9:18:23 AM9/15/09
to sphin...@googlegroups.com
oh ok! i can modify the css. i was looking for a sphinx configuration or something but that makes more sense anyways, thanks a bunch

Firat Ozgul

unread,
Sep 15, 2009, 9:11:16 AM9/15/09
to sphin...@googlegroups.com
Maybe you can do the wrapping via css. Just add these lines to "pre" tag. It works for me:

white-space : pre-wrap; /*for Mozilla*/
word-wrap: break-word; /*for IE*/



2009/9/15 Elaine Angelino <elaine....@gmail.com>
Reply all
Reply to author
Forward
0 new messages