Difference between revisions of "Syntax Highlighting Examples"
Jump to navigation
Jump to search
Omei Qunhua (talk | contribs) m (Undo revision 1187318 by Special:Contributions/Kireji Haiku) undo silly pointless edit that nigh-on hid the TOC) |
|||
Line 1: | Line 1: | ||
{{Help|Wiki=*}} | {{Help|Wiki=*}} | ||
== Overview == | == Overview == | ||
This is a | This is a MediaWiki extension that enables including code with syntax highlighting. To use, it, enclose your code in tags like this | ||
< | <syntaxhighlight lang="html4strict"> | ||
<Language> | <source lang="Language"> | ||
.... | .... | ||
</Language> | </source> | ||
</ | </syntaxhighlight> | ||
or | |||
<source lang="html4strict"> | |||
<syntaxhighlight lang="Language"> | |||
.... | |||
</syntaxhighlight> | |||
</source> | |||
where Language is the code for the programming or markup language being used. | where Language is the code for the programming or markup language being used. (Both forms work the same way, <syntaxhighlight> is handy for when the source code example itself contains a <source> tag.) | ||
The [http://www.mediawiki.org/wiki/Extension: | The [http://www.mediawiki.org/wiki/Extension:SyntaxHighlight_GeSHi documentation] lists a large number of supported languages, but the ones most likely to be useful here are | ||
* lsl2: Linden Scripting Language | |||
* cpp: C++ | * cpp: C++ | ||
* bash: Bash shell | * bash: Bash shell | ||
* html4strict: HTML | * html4strict or html5: HTML | ||
* javascript: Javascript | * javascript: Javascript | ||
* perl: Perl | * perl: Perl | ||
Line 24: | Line 31: | ||
== LSL == | == LSL == | ||
< | <source lang="lsl2"> | ||
if (type == 0) | if (type == 0) | ||
{ | { | ||
Line 34: | Line 41: | ||
} | } | ||
... | ... | ||
</ | </source> | ||
== PHP == | == PHP == | ||
Text before code. | Text before code. | ||
<php><?php | <source lang="php"><?php | ||
$v = "string"; // sample initialization | $v = "string"; // sample initialization | ||
?> | ?> | ||
Line 44: | Line 51: | ||
<? | <? | ||
echo $v; // end of php code | echo $v; // end of php code | ||
?> </ | ?> </source> | ||
Text after code. | Text after code. | ||
Line 50: | Line 57: | ||
Text before code. | Text before code. | ||
<python> # Hello World in Python | <source lang="python"> # Hello World in Python | ||
def main(): | def main(): | ||
Line 56: | Line 63: | ||
if __name__ == '__main__': | if __name__ == '__main__': | ||
main()</ | main()</source> | ||
Text after code. | Text after code. | ||
Line 63: | Line 70: | ||
Text before code. | Text before code. | ||
<cpp>#include <iostream> | <source lang="cpp">#include <iostream> | ||
int main(int argc, char** argv) | int main(int argc, char** argv) | ||
Line 69: | Line 76: | ||
std::cout << "hai, can i haz c++ nao?" << std::endl; | std::cout << "hai, can i haz c++ nao?" << std::endl; | ||
return 0; | return 0; | ||
}</ | }</source> | ||
Text after code. | Text after code. | ||
Line 76: | Line 83: | ||
Text before code. | Text before code. | ||
<html4strict><h1>OMG Look at This</h1> | <source lang="html4strict"><h1>OMG Look at This</h1> | ||
<p class="youknowsit">Wait where did he get that penguin from?</p></ | <p class="youknowsit">Wait where did he get that penguin from?</p></source> | ||
Text after code. | Text after code. |
Latest revision as of 01:20, 8 April 2015
Help Portal: |
Avatar | Bug Fixes | Communication | Community | Glossary | Land & Sim | Multimedia | Navigation | Object | Video Tutorials | Viewer | Wiki | Misc |
Overview
This is a MediaWiki extension that enables including code with syntax highlighting. To use, it, enclose your code in tags like this
<source lang="Language">
....
</source>
or
<syntaxhighlight lang="Language">
....
</syntaxhighlight>
where Language is the code for the programming or markup language being used. (Both forms work the same way, <syntaxhighlight> is handy for when the source code example itself contains a <source> tag.)
The documentation lists a large number of supported languages, but the ones most likely to be useful here are
- lsl2: Linden Scripting Language
- cpp: C++
- bash: Bash shell
- html4strict or html5: HTML
- javascript: Javascript
- perl: Perl
- php: PHP
- python: Python
- sql: SQL
- xml: XML
LSL
if (type == 0)
{
llOwnerSay("Near");
}
else if (type == 1)
{
llOwnerSay("Stopping");
}
...
PHP
Text before code.
<?php
$v = "string"; // sample initialization
?>
html text
<?
echo $v; // end of php code
?>
Text after code.
Python
Text before code.
# Hello World in Python
def main():
print "Hello World!"
if __name__ == '__main__':
main()
Text after code.
C++
Text before code.
#include <iostream>
int main(int argc, char** argv)
{
std::cout << "hai, can i haz c++ nao?" << std::endl;
return 0;
}
Text after code.
HTML
Text before code.
<h1>OMG Look at This</h1>
<p class="youknowsit">Wait where did he get that penguin from?</p>
Text after code.