Syntax Highlighting: Difference between revisions

info on highlighting source code
 
m Text replacement - "<(\/?)source" to "<$1syntaxhighlight"
 
(4 intermediate revisions by 2 users not shown)
Line 1: Line 1:
{{Feature
|image=Syntax.jpg
|imgdesc=Code highlighting
|title=
}}
{{#set:feature description = syntax highlighting is available for dozens of languages through the [[mw:Extension:SyntaxHighlight_GeSHi]] and the underlying [[Python]] [http://pygments.org/ Pygments] library }}
{{#set:feature notes =  }}
{{#set:feature tests =  }}
{{#set:feature examples = [[Apache]] shows config file highlighting; [[Library]] shows JavaScript; etc. }}
== Syntax Highlighting in Quanta ==
== Syntax Highlighting in Quanta ==
Quanta has syntax defintion files which are called 'DTEP' files.
Quanta has syntax defintion files which are called 'DTEP' files.
See the quanta dev list, website, or help:/quanta (Quanta Manual in konqueror).  These files are stored in
See the quanta dev list, website, or help:/quanta (Quanta Manual in konqueror).  These files are stored in
<source lang="bash">
<syntaxhighlight lang="bash">
# application directory
# application directory
/usr/share/apps/quanta/dtep/
/usr/share/apps/quanta/dtep/
# local user directory
# local user directory
~/.kde/share/apps/quanta/dtep/
~/.kde/share/apps/quanta/dtep/
</source>
</syntaxhighlight>
placing a new directory, which includes all tag definitions, in one of those locations will provide all the info Quanta needs to understand the syntax.  On the Quanta site there is a DTEP for TaskJuggler syntax.
placing a new directory, which includes all tag definitions, in one of those locations will provide all the info Quanta needs to understand the syntax.  On the Quanta site there is a DTEP for TaskJuggler syntax.


== Syntax Highlighing in VIM ==
== Syntax Highlighing in VIM ==
To add syntax highlighting for a particular language or syntax, you need to have a syntax definition file, and then you need to 'turn it on' by setting it up in your local configuration file.  For example, there is a syntax file for TaskJuggler, which can be turned on thusly:
To add syntax highlighting for a particular language or syntax, you need to have a syntax definition file, and then you need to 'turn it on' by setting it up in your local configuration file.  For example, there is a syntax file for TaskJuggler, which can be turned on thusly:
<source lang="bash">
<syntaxhighlight lang="bash">
sudo cp /usr/local/src/taskjuggler-2.2.0/Contrib/vim/tjp.vim  /usr/share/vim/vimcurrent/syntax/
sudo cp /usr/local/src/taskjuggler-2.2.0/Contrib/vim/tjp.vim  /usr/share/vim/vimcurrent/syntax/
sudo chmod o+r /usr/share/vim/vimcurrent/syntax/tjp.vim
sudo chmod o+r /usr/share/vim/vimcurrent/syntax/tjp.vim
Line 20: Line 31:
augroup END
augroup END
endif' >> ~/.vimrc
endif' >> ~/.vimrc
</source>
</syntaxhighlight>


== Syntax Highlighting in Konsole ==
== Syntax Highlighting in Konsole ==
Line 28: Line 39:


== Syntax Highlighting in MediaWiki ==
== Syntax Highlighting in MediaWiki ==
Writing good code, especially in open source context, requires illustrating best practices and tutorials.  Those tutorials are made ever more useful with syntax-highlighting.
(Note that there is also a [[MediaWiki/Syntax highlighting]] article)
Writing good code, especially in open source context, requires illustrating best practices and tutorials.  Those tutorials are made ever more useful with syntax highlighting.


MediaWiki is able to incorporate a nice 3rd-party project called [http://qbnz.com/highlighter/faq.php Generic Syntax Highlighter] or GeSHi for short.  Fortunately GeSHi is now packaged with debian for easy installation on Debian or Debian-based systems.  There is a [[mw:Extension:SyntaxHighlight_GeSHi]] extension which provides a tie-in between MediaWiki and GeSHi. (note that there are a few different GeSHi extensions for mediawiki, and we use the one in use on mediawiki.org http://www.mediawiki.org/wiki/Special:Version).
MediaWiki is able to incorporate a nice 3rd-party project called [http://qbnz.com/highlighter/faq.php Generic Syntax Highlighter] or GeSHi for short.  Fortunately GeSHi is now packaged with debian for easy installation on Debian or Debian-based systems.  There is a [[mw:Extension:SyntaxHighlight_GeSHi]] extension which provides a tie-in between MediaWiki and GeSHi. (note that there are a few different GeSHi extensions for mediawiki, and we use the one in use on mediawiki.org http://www.mediawiki.org/wiki/Special:Version).


To install the actual GeSHi software package (it installs in /usr/share)
To install the actual GeSHi software package (it installs in /usr/share)
<source lang="bash">
<syntaxhighlight lang="bash">
sudo apt-get install php-geshi
sudo apt-get install php-geshi
ls /usr/share/php-geshi/
ls /usr/share/php-geshi/
contrib  geshi  geshi.php
contrib  geshi  geshi.php
</source>
</syntaxhighlight>


Incorporating GeSHi into Mediawiki is just a matter of adding the extension to the source tree and including it in LocalSettings.
Incorporating GeSHi into Mediawiki is just a matter of adding the extension to the source tree and including it in LocalSettings.
Line 43: Line 55:
=== Usage ===
=== Usage ===
See the [[mw:Extension:SyntaxHighlight_GeSHi#Examples]]
See the [[mw:Extension:SyntaxHighlight_GeSHi#Examples]]


<nowiki>
<nowiki>
<source lang="php">
<syntaxhighlight lang="php">
     $v = array_pop($foo);    // just a comment
     $v = array_pop($foo);    // just a comment
</source>
</syntaxhighlight>
</nowiki>  
</nowiki>