Template:CssPre

From HorizonXI Wiki

Introduction

This template is for generating a PRE element or other HTML element with pre-defined styles to help with readability.

Custom parameters are also available.


Usage

Syntax

{{CssPre|<width>|<font-size>|<pad-size>|tag=<element>|b=<value>|t=<value>|custom=<style>|content=<value>}}

{{CssPre|<width>|<font-size>|<pad-size>|tag=<element>|b=<value>|t=<value>
  | custom = <style>
  | content = <value>
}}

Parameters

All parameters are optional.

  • Named Parameters
    • tag: The name of the HTML element to be rendered.
      Default value is pre.
    • b: Set to n to indicate that the element is not a block-level element, such as tag=code.
      By doing so, the display, white-space and word-wrap styles will be suppressed.
    • t: Set to y to indicate that the content is a template.
      By doing so, leading and trailing braces will be output.
    • custom: Any custom CSS you want to be included in the style attribute.
      Each style must be properly formatted: <name>:<value>;
    • content: Anything that should appear within the element.
      When providing Wikitext that should not be interpreted, surrounded the content with <nowiki></nowiki> tags. (see example)
  • Unnamed Parameters
  1. width: The value for the width. Default value is 80%
    The value is used exactly as it is provided.
    To prevent this parameter from being used, set it to 0.
    This should be done for inline elements such as tag=code.
  2. font-size: The value for the font-size (measured in em). Default value is 1.2
  3. pad-size: The value for the padding (measured in em). Default value is 1

Examples

No Style

  • Standard PRE block without a style attribute.
<pre>
{{MyTemplate
  | parm1 = 
  | parm2 = 
}}
</pre>

Output:

{{MyTemplate
  | parm1 = 
  | parm2 = 
}}

With CssPre

  • Basic example with only the t and content parameters provided.
{{CssPre|t=y
| content = <nowiki>MyTemplate
  | parm1 = 
  | parm2 = </nowiki>
}}

Output:

{{MyTemplate
  | parm1 = 
  | parm2 = 
}}

Custom CSS

  • Changes the font color to blue using custom.
{{CssPre|t=y|custom=color:blue;
| content = <nowiki>MyTemplate
  | parm1 = 
  | parm2 = </nowiki>
}}

Output:

{{MyTemplate
  | parm1 = 
  | parm2 = 
}}

Sizes

  • Custom size overrides
  1. Width = 50%
  2. Font = 1.5
  3. Padding = 2
{{CssPre|50%|1.5|2|t=y
| content = <nowiki>MyTemplate
  | parm1 = 
  | parm2 = </nowiki>
}}

Output:

{{MyTemplate
  | parm1 = 
  | parm2 = 
}}

Inline Element

  • A CODE element.
{{CssPre|tag=code|b=n|t=y|0||0.1
  | content = <nowiki>SimpleTemplate|parm1|parm2</nowiki>
}}

Output:

{{SimpleTemplate|parm1|parm2}}


Default Output

<pre style="display:inline-block;width:80%;white-space:pre-wrap;word-wrap:break-word;font-size:1.2em;padding:1em;"></pre>