Including a source code file within the wiki

From Alliance Doc
Revision as of 15:42, 23 March 2016 by Mboisson (talk | contribs)
Jump to navigation Jump to search
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 paramter). 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"


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"