Home
Categories
Dictionary
Download
Project Details
Changes Log
What Links Here
How To
Syntax
FAQ
License

pre



The "pre" element allows to enter several lines of unformatted text (keeping the white spaces). However it is possible to specify part of the text in a different font or color by using the font element.

Pre element background


It is possible to put a colored background under the "pre" element with the "boxed" or "border" attribute[1]
It is not allowed to have both the "boxed" and "border" attributes on the "pre" element
. This attribute can have the following values[2]
Note that it is possible to set a background for all pre elements. See code, pre and source background for more information
:
  • "true" or "simple": the "pre" element will have a colored background bordered by simple line
  • "simple": the "pre" element will have a simple border with a background color
  • "shadow" or "softShadow" : the "pre" element will have a soft shadowed border
  • "strongShadow": the "pre" element will have a strong shadowed border
  • "false" or "noBorder" : (the default) no border
The "color" attribute allows to fill the "pre" element with a color. If this attribute is not present:
  • By default of if the preHasBackground property is set to true, then a default background color will be used for the "simple" and "shadow" values
  • If the preHasBackground property is set to false, then no background color will be used for the "simple", "softShadow", "strongShadow", and "shadow" values


For example:
   <pre border="simple" >
   This is a text with a simple border.
   </pre>
has the following result:
      This is a text with a simple border.
 <pre border="shadow" >
 This is a text with a soft shadowed border.
 </pre>
has the following result:
      This is a text with a soft shadowed border.
 <pre color="#FFFF00" >
 This is a text with a yellow background.
 </pre>
has the following result:
      This is a text with a yellow background.
 <pre border="shadow" color="#FFFF00" >
 This is a text with a yellow background.
 </pre>
has the following result:
      This is a text with a yellow background and a shadow.

Pre scrolling type

The "scrollingType" attribute specifies how the content of the "pre" element is scrolled:
  • If the value is default (or by default if the attribute is not present), the value of the command-line preScrollingType or configuration file will be used
  • If the value is "unlimited", the content will not be limited on the page
  • If the value is "scrolled", the content will be scrolled with a scroll bar if too wide
  • If the value is "wrapped", the content will be wrapped if too wide

Note that if the "pre" element has a background, the "pre" will be scrolled regardless of the value of this attribute.


For example:
      This is a very long text with an unlimited scrolling type, there is no scroll bar and no wrapping for words.
      This is a very long text with a scrolled scrolling type, there is a scroll bar in this case to adapt the text length.
      This is a very long text with a wrapped scrolling type, there is no scroll bar and the text is wrapped.

Handling of invisible characters

The "invisibleChars" attribute specifies if the usage of "invisible characters" is allowed. See syntax highlighting for more information.

Content

There are two ways to define the content of the pre:
  • Put the content as CDATA inside the pre element. Such as for example:
       <pre>
                my pre content
       </pre>
    
    In this case, you will need to escape the < and > characters if they appear in the content.
  • Or specify an URL where the content of the pre will be defined. For example:
       <pre url="thePreFile" />
    
    Here the preFile is a file which is under the doc-files sub-directory and contain the same "my pre content" text. In this case, you don't need to escape the < and > characters if they appear in the content[3] .

Relaxed syntax

It is possible to allow directly any XML content inside the "pre" element by setting the "relaxedSyntax" property on the command-line or the configuration file. See Relaxed syntax for more information.

For example the following content is not allowed if the "relaxedSyntax" property is not set but is allowed if it is set:
  <pre>
  first line
  <parent name="name">
     <child name="child" />
  </parent>
  second line
  </pre>

Syntax hightlighting

Main Article: Syntax highlighting

It is possible to use syntax highlighting on the "pre" content by specifying the "syntax" property. See syntax highlighting for more information.

For example:
<pre syntax="java">
   public void toto(int i) {
   _ System.out.println(i);
   }
</pre>
will have the following result:
   public void toto(int i) {
     System.out.println(i);
   }
or:
<pre syntax="xml">
   <parent name="name">
     <child name="child" />
   </parent>
</pre>
will have the following result:
   <parent name="name">
      <child name="child" />
   </parent>
It is possible to use the "font" element with syntax hightlighting. For example:
   <pre syntax="xml">
      <parent name="name">
      the text with a <font background="yellow">yellow background</font>
      </parent>
   </pre>
It is also possible to use the "i" or "b" elements with syntax hightlighting. For example:
   <pre syntax="xml">
      <parent name="name">
      the text with a <b>bold font</b>
      </parent>
   </pre>
will have the following result:
      <parent name="name">
      the text with a yellow background
      </parent>

Handling of the space at the left before the spans

The parser tries to reduce the space before the actual text in each line if possible.

For example:
  <table>
     <row>
        <cell>Example for the <code>following</code> content:
           <pre syntax="xml">
             <literal name="A661_ANIMATION_GROUP" value="A1E3"/>
             <literal name="A661_ANIMATION_GROUP" value="A1E4"/>         
           </pre>
        </cell>
     </row>              
  </table>
will have the following result (rather than having a lot of spaces before each line span in the pre):
Example for the following content:
   <literal name="A661_ANIMATION_GROUP" value="A1E3"/>
   <literal name="A661_ANIMATION_GROUP" value="A1E4"/>

Examples

Basic example

  <pre>
  first line
  second line
  </pre>
Result:
      first line
      second line

Using color

  <pre>
  first line in <font color="blue">blue</font>
  second line
  </pre>
Result:
      first line in blue
      second line

Boxed pre

  <pre boxed="true">
  first line
  second line
  </pre>
Result:
      first line
      second line
 <pre color="#FFFF00" boxed="true">
 first line
 second line
 </pre>
Result:
      first line
      second line

Adding a shadow

  <pre boxed="shadow">
  first line
  second line
  </pre>
Result:
      first line
      second line

Using syntax highlighting

   <pre syntax="java">
      public void toto(int i) {
      _ System.out.println(i);
      }
   </pre>
will have the following result:
   public void toto(int i) {
     System.out.println(i);
   }

Specifying the content in an external file

  <pre url="myPre" />
With the following content for the myPre file under the doc-files directory[3] :
      first line
      second line
Result:
      first line
      second line

Notes

  1. ^ It is not allowed to have both the "boxed" and "border" attributes on the "pre" element
  2. ^ Note that it is possible to set a background for all pre elements. See code, pre and source background for more information
  3. ^ [1] [2] see doc-files

See also


Categories: syntax

docJGenerator Copyright (c) 2016-2023 Herve Girod. All rights reserved.