Difference between revisions of "Using code highlighting with MediaWiki pages"
Jump to navigation
Jump to search
m |
m |
||
Line 1: | Line 1: | ||
=== Prologue === | === Prologue === | ||
We're using an extension called [https://www.mediawiki.org/wiki/Extension:SyntaxHighlight SyntaxHighlight] | We're using an extension called [https://www.mediawiki.org/wiki/Extension:SyntaxHighlight SyntaxHighlight]. | ||
<br>This guide will show you how to use it and how to find the names for the languages, so SyntaxHighlight knows what it's highlighting. | <br>This guide will show you how to use it and how to find the names for the languages, so SyntaxHighlight knows what it's highlighting. | ||
Latest revision as of 00:11, 28 February 2021
Prologue
We're using an extension called SyntaxHighlight.
This guide will show you how to use it and how to find the names for the languages, so SyntaxHighlight knows what it's highlighting.
HTML Syntax
Without line numbers
This one is useful if you expect the reader to copy the code.
<syntaxhighlight lang="apacheconf"> RewriteEngine On RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^(.*)$ index.php?title=$1 [NC,L,QSA] </syntaxhighlight>
With line numbers
This one can be useful if you want to refer to a line of code.
<syntaxhighlight lang="apacheconf" line> RewriteEngine On RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^(.*)$ index.php?title=$1 [NC,L,QSA] </syntaxhighlight>
You can also specify on which line to start counting.
<syntaxhighlight lang="apacheconf" line start="55"> RewriteEngine On RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^(.*)$ index.php?title=$1 [NC,L,QSA] </syntaxhighlight>
Finding language names
You can do so by going to this page: https://pygments.org/docs/lexers/
You'll want to search on the page for the language you want to highlight. Then look for the "Short names" and pick one.
Insert the short name in the "lang" parameter and the text inside the <syntaxhighlight> block will be highlighted accordingly.