Template:CB

From VASP Wiki
{{{1}}}

Purpose

Create a code block which can be indented with the usual : indentation marker. Normally, a preformatted text block can be inserted with an additional space in the beginning, e.g.

 MY_SPECIAL_TAG = A B C

will print as:

MY_SPECIAL_TAG = A B C

However, this syntax does not allow indenting, e.g., in lists. The CB (as in Code Block) template allows the box to be indented any level.

Warning: There are some unresolved issues with this template, see bottom of this page.

Parameters

 {{CB|<content>|<<indent>>|<<padding>>}}
  • content: The content of the code block.
  • indent: (optional) Allows to indent the whole box with regular colon sign. Use multiple ":" signs to get any level of indentation. Can be left empty if no indentation is needed but padding is required. Any other character than ":" may produce unexpected results!
  • padding: (optional) Specifies the padding of the code box, the default is 1em.

Examples

Without optional arguments the following example

{{CB|MY_SPECIAL_TAG {{=}} A B C}}

gives:

MY_SPECIAL_TAG = A B C

This should be very close to the regular preformatted text boxes we can obtain via MediaWiki syntax. Here are two examples for indentation levels:

{{CB|MY_SPECIAL_TAG {{=}} A B C|:}} 
{{CB|MY_SPECIAL_TAG {{=}} A B C|::}}

results in:

MY_SPECIAL_TAG = A B C
MY_SPECIAL_TAG = A B C

Note that the boxes are correctly indented one and two levels. The padding can be reduced with the optional argument, e.g.:

{{CB|MY_SPECIAL_TAG {{=}} A B C|:|0.5em}} 
{{CB|MY_SPECIAL_TAG {{=}} A B C|::|0.5em}}

gives this:

MY_SPECIAL_TAG = A B C
MY_SPECIAL_TAG = A B C

Finally, the padding can also be specified without any indentation:

{{CB|MY_SPECIAL_TAG {{=}} A B C||0.5em}} 

shows as:

MY_SPECIAL_TAG = A B C

Problems and workarounds

The content cannot contain the "=" or "|" character because this has a special meaning for named template parameters. Therefore, we have to use the {{=}} and {{!}} template, respectively.

Demonstration with complex contents

MediaWiki syntax:

ML_MODE Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet.
Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet.   

Duis autem vel eum iriure dolor in hendrerit in vulputate velit esse molestie consequat, vel illum dolore eu feugiat nulla facilisis at vero eros et accumsan et iusto odio dignissim qui blandit praesent luptatum zzril delenit augue duis dolore te feugait nulla facilisi. Lorem ipsum dolor sit amet,

This template with indentation level 2:

ML_MODE Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet.

Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet.

Duis autem vel eum iriure dolor in hendrerit in vulputate velit esse molestie consequat, vel illum dolore eu feugiat nulla facilisis at vero eros et accumsan et iusto odio dignissim qui blandit praesent luptatum zzril delenit augue duis dolore te feugait nulla facilisi. Lorem ipsum dolor sit amet,

Unsolved problems

Multi-line code blocks seem to give wrong line spacing depending on placement of newlines in the content:

blabla blabla blabla blabla blabla

blabla

blabla blabla blabla blabla

blabla

blabla blabla blabla

blabla


blabla

blabla

blabla

blabla

blabla