Including a source code file within the wiki

From CC Doc
Jump to: navigation, search
Other languages:
English • ‎français

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"


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

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