Codeblock

The code directive allows to display code areas in the comment. These are shaded gray in the Library Manager and displayed in monospaced font with color-coded syntax.

Description

The directive markup consists of an explicit markup start (".. ") followed by the type of the directive (code) and two colons.

(See also: Directives)

Principle

.. code::

Properties

  • A blank line is required between the directive and a preceding text body element (for example, a paragraph with text).

Options

Optionally, a directive block can contain a flat list of code options. The following option is recognized:

Number lines : [start line number]

Each line is preceded by a line number. The optional argument is the number of the first line. Default value is 1.

The syntax is not highlighted in color in this case.

Samples

(In sample project: B_DocuElements\Code Block\FB_Libdoc_CodeBlock)

Code block with color-coded syntax

(*
.. code:: 
    
    // Attempts to return the value of a boolean property.
   
    FUNCTION GetBooleanProperty : BOOL
    VAR_INPUT
        sKey: STRING;
    END_VAR

    // This structure defines a special profile.

    TYPE ST_Profile :
    STRUCT
        nId     : INT := -1;
        sBuffer : STRING(255) := 'Hello';
    END_STRUCT
    END_TYPE
*)

Codeblock 1:

Code block with line numbering

(*
.. code:: 
   :number-lines: 1
    
    // Attempts to return the value of a boolean property.
   
    FUNCTION GetBooleanProperty : BOOL
    VAR_INPUT
        sKey: STRING;
    END_VAR

    // This structure defines a special profile.

    TYPE ST_Profile :
    STRUCT
        nId     : INT := -1;
        sBuffer : STRING(255) := 'Hello';
    END_STRUCT
    END_TYPE
*)

Codeblock 2: