shay has asked for the wisdom of the Perl Monks concerning the following question:
This question is possibly a little off-topic in that it doesn't directly concern Perl, but the issue keeps cropping up for me in CGI/mod_perl work with Perl.
I usually have some means of displaying the full text of error messages in the web browser during development, often including pieces of code, e.g. stacktraces. Due to the presence of pieces of code, such messages are usually best displayed in a fixed-width font and benefit from whitespace being preserved rather than crunched as in HTML. The simplest way to achieve this is to use <pre> tags, after first running the message text through something like Apache::Util::escape_html() to escape unsafe HTML characters.
However, the problem with <pre> tags is that the text within them, being interpreted as "pre-formatted", doesn't get wrapped to the web browser window. Using <code> tags instead gives the desired wrapping effect, but then whitespace gets crunched.
I don't see any other HTML tags that would be of use (there is a (non-standard) <xmp> tag for "example" code which behaves like <pre> and does escaping of unsafe charcaters too, but still doesn't wrap to the window), so the text probably needs processing in Perl first, and then maybe displaying with <code> tags.
Currently I'm thinking of changing newlines to <br> tags and spaces to entities (after escaping unsafe characters first) and then using <code> tags, but I wondered if others had a more elegant way of doing this.
- Steve
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
•Re: Formatting CGI script error messages
by merlyn (Sage) on Nov 17, 2004 at 12:39 UTC | |
by shay (Beadle) on Nov 17, 2004 at 12:57 UTC | |
|
Re: Formatting CGI script error messages
by jobi (Scribe) on Nov 17, 2004 at 12:35 UTC | |
by shay (Beadle) on Nov 17, 2004 at 12:49 UTC | |
|
Re: Formatting CGI script error messages
by hostyle (Scribe) on Nov 17, 2004 at 15:56 UTC | |
by shay (Beadle) on Nov 17, 2004 at 16:46 UTC | |
by Anonymous Monk on Nov 18, 2004 at 03:31 UTC | |
|
Re: Formatting CGI script error messages
by TedPride (Priest) on Nov 17, 2004 at 12:59 UTC | |
by shay (Beadle) on Nov 17, 2004 at 13:08 UTC | |
by ww (Archbishop) on Nov 17, 2004 at 14:00 UTC |