-

Note: You are currently viewing documentation for Moodle 3.10. Up-to-date documentation for the latest stable version of Moodle may be available here: Code syntax highlighting.

Code syntax highlighting: Difference between revisions

From MoodleDocs
m (Code Syntax Highlighting moved to Code syntax highlighting)
No edit summary
 
(12 intermediate revisions by 8 users not shown)
Line 1: Line 1:
You can color or highlight code snippets within Moodle resources, forum posts etc. To do so you must install the GeSHi (Generic Syntax Highlighter) Filter. This makes the power of GeSHI available in Moodle through the use of a pair of special tags.
There used to be [https://moodle.org/plugins/view.php?plugin=filter_geshi filter_geshi] available for the syntax highlighting but is was [https://tracker.moodle.org/browse/CONTRIB-8002 removed].
 
See [[MoodleDocs:Style_guide#PHP_syntax_highlighting]] that does not need any additional filter
== Installing ==
 
You can download the GeSHi filter from here:
 
http://geshi.org/downloads/geshi.zip
 
Then follow the instructions for [[Installing a Filter]].
 
== Instructions for use ==
 
Enclose your code in spans like so:
 
<nowiki><span syntax="langname"> your code goes here </span> </nowiki>
 
=== Supported languages ===
 
* asm,
* bash,
* cpp,
* [[CSS]]
* lisp
* matlab
* [[HTML]]
* [[PHP]]
* pascal
* xml
 
and many others. See the GeSHi homepage for full details.
 
=== options ===
 
You can add the following options to the span tags in the same way you would add HTML attributes. The syntax attribute, specifying the programming language, must come first and all others are optional.
 
* linenumbers="yes" - displays linenumbers, defaults to "no"
* urls="no" - switches off keyword to URL conversion, defaults to "yes"
* indentsize="num" - alters the width of tabs, measured in characters/columns, default is ?
 
Example with options:
 
<nowiki> <span syntax="langname" linenumbers="yes" urls="no" indentsize="2"> </nowiki>
 
== Demo ==
 
The filter has recently been installed on Moodle.org and can be seen in use there. For example see this post:
 
http://moodle.org/mod/forum/discuss.php?d=25413#195644
 
The GeSHi homepage also has an interactive demo.
 
http://qbnz.com/highlighter/demo.php
 
== See also ==
 
* [http://moodle.org/mod/forum/discuss.php?d=25413 Forum post introducing the Filter]
* [http://moodle.org/mod/forum/discuss.php?d=43266 Forum thread for progress reports and feedback]
* [http://qbnz.com/highlighter/ GeSHi homepage]


[[Category:Administrator]]
[[Category:Administrator]]
[[Category:Filter]]
[[Category:Filter]]
[[es:Resaltado de sintaxis de codigo]]

Latest revision as of 09:03, 9 March 2020

There used to be filter_geshi available for the syntax highlighting but is was removed. See MoodleDocs:Style_guide#PHP_syntax_highlighting that does not need any additional filter