Including a source code file within the wiki

From Alliance Doc
Jump to navigation Jump to search
This site replaces the former Compute Canada documentation site, and is now being managed by the Digital Research Alliance of Canada.

Ce site remplace l'ancien site de documentation de Calcul Canada et est maintenant géré par l'Alliance de recherche numérique du Canada.

Other languages:

As explained on the page Including source code within the wiki, you can include source code within the wiki using the <syntaxhighlight> </syntaxhighlight> tag. If you want to separate the code a bit more from the rest of the text, you can use the {{File}} template. This template takes as argument the file name (name parameter), the language of the file (lang parameter) and the content of the file (contents parameter). The default language for this template is bash.

For example,

{{File
  |name=myfile.sh
  |lang="bash"
  |contents=
#!/bin/bash
echo "this is a bash script"
}}

results in:

File : myfile.sh

#!/bin/bash
echo "this is a bash script"


Special characters: Pipe, equals

Certain characters that frequently appear in bash scripts are also meaningful to the Mediawiki template parser.

  • If the source code contains a pipe character, |, replace it with {{!}}.
  • In some circumstances you may find it necessary to replace the equal sign, =, with {{=}}.

Displaying line numbers

To display line numbers, you can add the option "|lines=yes". For example,

{{File
  |name=monfichier.sh
  |lang="bash"
  |lines=yes
  |contents=
#!/bin/bash
echo "this is a bash script"
}}

results in:

File : myfile.sh

#!/bin/bash
echo "this is a bash script"