Template:Pre
Sample text
| This template uses TemplateStyles: |
This template implements a version of the functionality provided by the HTML <pre> tag.
Usage
This template supports two parameters
|width= The width of the pre "box"
|space= The way white space is handled in the pre "box"
| Markup | Renders as |
|---|---|
{{Pre|
This Pre-format
can look
like this.
}} |
This Pre-format can look like this. |
Main differences include:
- It wraps text that overflows the page.
- It allows mid-line-breaks (but not always consistently).
Main limitations include:
- If the text is a single long word, it won't be wrapped and will still break out to the right hand of the page.
- HTML and wikimarkup aren't disabled as in
<pre>...</pre>and are rendered as usual (thus if a parameter contains any wikimarkup, enclose it in<nowiki>...</nowiki>); however, multiple spaces are preserved.
As with <pre> and <code>, {{pre}} displays text in the font specified as the monospace font in the user's browser options, or specified in the user's CSS pages.
Example
Markup
{{Pre|
'''First line, markup working:''' and HTML comment <!--HIDDEN--> hidden.
'''Second line, long text wrapping:''' all work and no play make jack a dull boy all work and no play make jack a dull boy all work and no play make jack a dull boy all work and no play make jack a dull boy all work and no play make jack a dull boy.
Pipes separate parameters, so literal pipes cannot be included.
^^^^^^^^^^^^^ Escape them as <nowiki>{{!}}</nowiki> and {{!}} it's {{!}} OK.
Similarly, {{=}} is the parameter/value separator so a literal {{=}} must be escaped as <nowiki>{{=}}</nowiki>.
<nowiki>Or, between <nowiki>...</nowiki>, you can include | whatever = you || want.</nowiki>
'''Fourth line, multiple spaces preserved''' unlike in HTML and wikitext.
'''Fifth line, following the previous one'''.
'''Last line''' preceded by two blank lines in markup and in display.
}}
- Result
First line, markup working: and HTML comment hidden.
Second line, long text wrapping: all work and no play make jack a dull boy all work and no play make jack a dull boy all work and no play make jack a dull boy all work and no play make jack a dull boy all work and no play make jack a dull boy.
Pipes separate parameters, so literal pipes cannot be included.
^^^^^^^^^^^^^ Escape them as {{!}} and | it's | OK.
Similarly, = is the the parameter/value separator so a literal = must be escaped as {{=}}.
Or, between <nowiki>...</nowiki>, you can include | whatever = you || want.
Fourth line, multiple spaces preserved unlike in HTML and wikitext.
Fifth line, following the previous one.
Last line preceded by two blank lines in markup and in display.
Technical details
Since revision 619441399, this template uses a hack to output the <pre> element. See phab:T353697#9470436 for details.
Maintenance categories
TemplateData
TemplateData for Pre
The {{pre}} template creates a block of preformatted text, suitable for code. It provides a version of the functionality of the HTML <pre>...</pre> tag. The main difference is that wikitext within the tag is not disabled, but processed normally. Thus, this template can be used to provide examples of code with styling, links, and so on.
| Parameter | Description | Type | Status | |
|---|---|---|---|---|
| Text | 1 | The text to wrap in <pre>...</pre> tags. The characters | and = must be escaped in one of several available ways, for instance as {{!}} and {{=}}, respectively. | Content | required |
| Border | border | Set to ‘no’ if there should be no border around the box.
| String | optional |
| Width | width | The width of the <pre> box in CSS syntax (argument to ‘width:’).
| String | optional |
| Space | space | Indicates how white space is handled in the <pre> box. Argument to the CSS white-space property.
| String | optional |
| Style | style | CSS code to apply to the <pre> tag. | String | optional |