Open main menu

Template:Prettypre


Use, Limitations, and OptionsEdit

UseEdit


Similar in use to the existing preformatting tags, but with styling options. The code to call the template and the result is shown below.

Example A Result A
{{Prettypre||border=1px solid gray|background:lightyellow|font=monospace|color=green|

a  b   c    d     e
f  g   h    i     j
k  l   m    n     o
p  q   r    s     t
u  v   w    x     y
z
}}

 
a  b   c    d     e
f  g   h    i     j
k  l   m    n     o
p  q   r    s     t
u  v   w    x     y
z

Example B:

The preformatted text template Pretext is used here as a parameter of Prettypre to show the formats; the template is called for use with:

{{prettypre|border=1px solid dimgray|background=papayawhip|width=400px|align=center|{{pretext}}}}


Result B:

******************************************************
*                                                    *
*                Preformatted Text                   *
*             ------------------------               *
*            When used  in  preformatting            *
* 0          tags with a  monospaced font,         0 *
* 00         this text block  and borders         00 *
* 000        should  be  straight, with a        000 *
* 0000       clean left-aligned edge.           0000 *
* 00000                                        00000 *
* 000000     The  quick  brown  fox jumps     000000 *
* 0000000    over  the  lazy  dog's  back.   0000000 *
* 00000000   The  time  has  come for all   00000000 *
* 000000000  good  men to come to the aid  000000000 *
*            of the party. (1234567890).             *
*                                                    *
*                                                    *
******************************************************


LimitationsEdit

There is a slight control of how overflow is handled, though care is still needed to shorten the preformatted text to fit the page, if it is not to project beyond the right border.

For those looking for a method to wrap long lines but preserve preformatting of other lines, the CSS Pre-wrap value of the White-space property will do this; at present Opera 8 and beyond support the value, Firefox 3 onwards supports it, and I am uncertain about Internet Explorer 7. Please consider these browser compatibility issues before modifying the code.

OptionsEdit

align
text alignment; left, right, or center. Default: left.
border
border, takes format eg; 1px solid black. Default: 0px.
background
block background color. Any. Default: transparent to give same as page.
color
font or foreground color. Any. Default: inherit from page
font
font family, size, style, etc. Default: inherit from page
overflow
sets how to handle text overflow. Visible, hidden, scroll, auto. Default: auto.
style
allow complete control over styling the preformatted box
width
block width, default 100%