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

Code syntax highlighting: Difference between revisions

From MoodleDocs
m (Undo revision 130962 by Enovationdevteam (talk))
 
(4 intermediate revisions by 2 users not shown)
Line 5: Line 5:
You can download the GeSHi filter from here:
You can download the GeSHi filter from here:


http://geshi.org/downloads/moodle-geshi-filter-0.1.0.zip
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.
To install, unzip that archive into your filter/ directory and then enable it in the admin filter configuration screen.
Line 11: Line 11:
== Instructions for use ==
== Instructions for use ==


WARNING: (This warning applies to Moodle 1.9.4. It may apply to other versions, but I have not tested to confirm) The GeSHI filter, while it does work, when used in conjunction with the HTML Editor, can be quirky, frustrating, and difficult to use. See my reproducible example, below.
Enclose your code in spans under the source of html editor like so:


Enclose your code in spans like so:
<nowiki><span syntax="code">your code goes here</span></nowiki>
 
<nowiki>[code lang]your code goes here [/code]
[code lang linenumbers]your code with line numbers [/code]
[code lang highlight=1,2,6-9]your code with lines 1, 2 and 6
  to 9 highlighted "extra" [/code]
[code lang linenumbers start=4]start the line numbers at "4" [/code]</nowiki>
 
=== Reproducible Example ===
 
To achieve good results in Moodle 1.9.4+, use the following steps:
 
# Type the GeSHI open/close tags -- "[code php][/code]" -- into the HTML editor (change "php" to another language as required)
#* No quotes, just SQUAREBRACKET-c-o-d-e-SPACE-p-h-p-SQUAREBRACKET
# Highlight these open/close GeSHI tags and choose "preformatted"
# Copy code from textual source
# Paste into HTML editor using source-HTML mode (click the "<>" button to switch modes). Paste '''in-between the [code][/code] brackets'''
# Save and return to course


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


=== Supported languages ===
=== Supported languages ===
Line 54: Line 38:


== Demo ==
== 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.
The GeSHi homepage also has an interactive demo.


http://qbnz.com/highlighter/demo.php
http://qbnz.com/highlighter/demo.php
== History ==
This filter used to use <nowiki><span syntax="language">...</span></nowiki> as markers for code. However this changed after conflicts with the HTMLArea editor became apparent.


== Development ==
== Development ==


The last development for this filter appears to have been in 2008. Suggestions for new features and bug reports are welcome, please post them in the [http://moodle.org/mod/forum/discuss.php?d=43266 discussion thread].
The last development for this filter appears to have been in 2008. 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://moodle.org/mod/forum/discuss.php?d=43266 Forum thread for progress reports and feedback]
* [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:43, 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 2008. Bug reports are welcome, please post them in the github issues system.

See also