[Zope] Re: Line Wrap and the Zope Community?
Paul Winkler
slinkp23@yahoo.com
Wed, 21 Nov 2001 15:12:57 -0500
On Wed, Nov 21, 2001 at 12:55:29PM -0600, Mike Renfro wrote:
> Now, some of the issues with structured text are being addressed
> (http://structuredtext.sourceforge.net/), but for our immediate
> crisis, who wants to come up with a solution that will:
>
> a) keep my code intact -- no extra line breaks, spaces, etc. unless I
> say so. No removals, either. If I print out a snippet of Python code
> that's been mis-indented because someone wanted a narrower page, I'll
> be irked.
It's a very tough problem. All these pages use table layouts; and even
if you specify table width as 100%, that doesn't *really* mean 100% of
the browser window - it means "100% of the browser window if
everything fits, otherwise, expand outside the window as necessary."
There's no way to prevent that from happening if an element of the
table is too big. And browsers aren't smart enough to allow one really
wide cell and still fit the rest of the table in the browser window.
There are 3 ways to get a row too wide for the browser window:
1) include a really wide image
2) include a "pre" tag with a really long line
3) include a really long string with no whitespace
4) specify table width as a really large number of pixels.
#4 is unlikely. On zope.org I think most of the problems are due to
#2, with possibly some screenshots accounting for #1. #3 might come up
if there's a link to a gargantuan URL.
We *can't* prevent all of these from happening. For one thing, we
never know what "really wide" means; somebody might be browsing on a
portable device with a 200x300 display. You can find out with
javascript ... *if* the client has javascript ... and *if* they
haven't turned it off ... and *if* it works...
Without knowing the display size, the best we can do is pick a
reasonable width and try to force most things to fit that width.
Two possible hacks that might help:
1) Modify stx such that normal (non-code) paragraphs are wrapped in a
table cell with an explicit width of reasonable size. Pick this
reasonable size empirically based on common browsers and displays.
It'll look better sometimes, and worse sometimes.
2) Modify stx such that normal (non-code) paragraphs do explicit line
wrapping using <br> tags. Again, pick a reasonable size empirically
based on common browsers and displays. This has the disadvantage that
it doesn't work if the user's preferences include some funky font
size. Here's an example function:
import string
def explicit_wrap(paragraph, maxlength):
input_words = string.split(paragraph)
lines = []
while input_words:
line = input_words[:]
while len(string.join(line, ' ')) > maxlength:
line.pop()
input_words = input_words[len(line):]
lines.append(string.join(line, ' '))
# handle the last line
if len(string.join(input_words, ' ')) <= maxlength:
lines.append(string.join(input_words, ' '))
break
result = string.join(lines, '<br>\n')
return result
--
paul winkler
home: http://www.slinkp.com
music: http://www.reacharms.com
calendars: http://www.calendargalaxy.com