Code syntax highlighting: Difference between revisions

From MoodleDocs
No edit summary
 
mNo edit summary
 
(16 intermediate revisions by 9 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.
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.


== Installing ==
== Installing ==


You can download the GeSHi filter from [http://moodle.org/file.php/5/moddata/forum/33/195637/geshi.zip here].
You can download the GeSHi filter from here:


Then follow the instructions for [[Installing a Filter]].
https://moodle.org/plugins/view.php?plugin=filter_geshi
 
To install, unzip that archive into your filter/ directory and then enable it in the admin filter configuration screen.


== Instructions for use ==
== Instructions for use ==


Enclose your code in spans like so:
Enclose your code in spans under the source of html editor like so:


<nowiki><span syntax="langname"> your code goes here </span> </nowiki>
<nowiki><span syntax="code">your code goes here</span></nowiki>
 
<nowiki><span syntax="code" linenumbers="yes">your code with line numbers</span></nowiki>


=== Supported languages ===
=== Supported languages ===
Line 21: Line 25:
* lisp
* lisp
* matlab
* matlab
* [[HTML]]
* [[HTML in Moodle]]
* [[PHP]]
* [[PHP]]
* pascal
* pascal
* sql
* xml
* xml


and many others. See the GeSHi homepage for full details.
and many others. See the GeSHi homepage for full details.


=== options ===
=== 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>


See the examples above. This filter is still under development so things may change.


== Demo ==
== Demo ==


The filter has recently been installed on Moodle.org and can be seen in use there. For example see this post:
The GeSHi homepage also has an interactive demo.


http://moodle.org/mod/forum/discuss.php?d=25413#195644
http://qbnz.com/highlighter/demo.php


The GeSHi homepage also has an interactive demo.
== Development ==


http://qbnz.com/highlighter/demo.php
The last development for this filter appears to have been in 2017. Bug reports are welcome, please post them in the [https://github.com/enovation/moodle-filter_geshi/issues github issues system].


== See also ==
== See also ==


[http://moodle.org/mod/forum/discuss.php?d=25413 Forum post introducing the Filter]
* [http://qbnz.com/highlighter/ GeSHi homepage]
[http://qbnz.com/highlighter/ GeSHi homepage]
* [[MoodleDocs:Style_guide#PHP_syntax_highlighting]] that does not need any additional filter


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

Latest revision as of 09:44, 14 May 2018

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.

Installing

You can download the GeSHi filter from here:

https://moodle.org/plugins/view.php?plugin=filter_geshi

To install, unzip that archive into your filter/ directory and then enable it in the admin filter configuration screen.

Instructions for use

Enclose your code in spans under the source of html editor like so:

<span syntax="code">your code goes here</span>

<span syntax="code" linenumbers="yes">your code with line numbers</span>

Supported languages

and many others. See the GeSHi homepage for full details.

Options

See the examples above. This filter is still under development so things may change.

Demo

The GeSHi homepage also has an interactive demo.

http://qbnz.com/highlighter/demo.php

Development

The last development for this filter appears to have been in 2017. Bug reports are welcome, please post them in the github issues system.

See also