github.com/coveo/gotemplate@v2.7.7+incompatible/docs/doc_test/literals.rendered (about)

     1  {% include navigation.html %}
     2  {% raw %}
     3  # Literals protection
     4  
     5  ## E-Mail protection
     6  
     7  The razor convertor is designed to detect email address such as `john.doe@company.com` or `alert@127.0.0.1`.
     8  
     9  But it you type something like `<no value><no value>`, it will try to resolve variable john.doe and company.com.
    10  
    11  The result would be `<no value><no value>` unless you have defined:
    12  
    13  ```go
    14  ```
    15  
    16  In that case, the result of `123.453.141592653589793` will be `123.453.141592653589793`.
    17  
    18  ## "&#64;" protection
    19  
    20  You can also render the "&#64;" characters by writing &#64;&#64;.
    21  
    22  So this `@` will render &#64;.
    23  
    24  ## "&#123;&#123;" protection
    25  
    26  You can also render "&#123;&#123;" without being interpretated by go template using the following syntax `{{`.
    27  
    28  So this `{{` will render &#123;&#123;.
    29  
    30  ## Space management
    31  
    32  With go template, the way to indicate that previous or leading spaces between expression should be removed is expressed
    33  that way `expression`. The minus sign at the beginning and at the end mean that the spaces should be remove while
    34  `expression` means to remove only at the beginning and `expression` means to remove only at the end.
    35  
    36  The `expression` will keep the spaces before and after expression as they are.
    37  
    38  With razor, assignation will render go template code with - on left side.
    39  
    40  * `` => ``
    41  * `` => ``
    42  
    43  But for variables and other expressions, you have to specify the expected behavior.
    44  
    45  | Razor expression | Go Template      | Note
    46  | ---------------- | -----------      | ----
    47  | `expression`          | `expression`   | No space eater
    48  | `expression`         | `expression`  | Left space eater
    49  | `expression`        | `expression`  | Right space eaters
    50  | `expression`        | `expression` | Left and right space eaters
    51  
    52  This signify that in the following sentence:
    53  
    54  ```text
    55      The word expression will stay in the normal flow,
    56      butexpression will be struck on the previous word
    57  ```
    58  
    59  results in:
    60  
    61  ```text
    62      The word expression will stay in the normal flow,
    63      butexpression will be struck on the previous one
    64  ```
    65  
    66  You can also specify that the expression should be preceded by a new line:
    67  
    68  ```text
    69      The word
    70  expression will be on a new line
    71  ```
    72  
    73  results in:
    74  
    75  ```text
    76      The word
    77      expression will be on a new line
    78  ```
    79  
    80  ### Indent using current indentation
    81  
    82  This line will be rendered with 4 spaces before each word:
    83  
    84  ```go
    85      This is a long
    86      line that should
    87      be rendered with
    88      a maximum 15
    89      characters per
    90      line
    91  ```
    92  
    93  results in :
    94  
    95  ```text
    96      This is a long
    97      line that should
    98      be rendered with
    99      a maximum 15
   100      characters per
   101      line
   102  ```
   103  
   104  While this line will be rendered with 4 spaces and a caret before each word:
   105  
   106  ```go
   107  list:
   108    - item 1
   109    - item 2
   110    - item 3
   111      - sub 1
   112      - sub 2
   113      - sub 3
   114  ```
   115  
   116  results in:
   117  
   118  ```text
   119    - item 1
   120    - item 2
   121    - item 3
   122      - sub 1
   123      - sub 2
   124      - sub 3
   125  ```
   126  
   127  While this line will be rendered with 4 spaces and `**` before each word:
   128  
   129  ```go
   130      ** item 1
   131      ** item 2
   132      ** item 3
   133  ```
   134  
   135  results in:
   136  
   137  ```text
   138      ** item 1
   139      ** item 2
   140      ** item 3
   141  ```
   142  
   143  It is also possible to automatically wrap list elements with the surrounding context:
   144  
   145  ```go
   146      => This is Item #[1]!
   147      => This is Item #[2]!
   148      => This is Item #[3]!
   149      => This is Item #[4]!
   150      => This is Item #[5]!
   151  ```
   152  
   153  results in:
   154  
   155  ```text
   156      => This is Item #[1]!
   157      => This is Item #[2]!
   158      => This is Item #[3]!
   159      => This is Item #[4]!
   160      => This is Item #[5]!
   161  ```
   162  
   163  {% endraw %}