Aquesta pàgina forma part de la documentació de Moodle en català, tot i que no ha estat traduïda encara. Podeu contribuir obertament a les tasques de traducció. Podeu consultar la Guia d'edició de la documentació i també participar ens els debats del fòrum de traductors de la documentació a moodle.org

Code syntax highlighting: diferència entre les revisions

De MoodleDocs
Salta a:navegació, cerca
m (Code Syntax Highlighting moved to Code syntax highlighting)
(New version of filter now has different embed method, updated this page to reflect that.)
Línia 5: Línia 5:
You can download the GeSHi filter from here:
You can download the GeSHi filter from here:


http://geshi.org/downloads/geshi.zip
http://geshi.org/downloads/moodle-geshi-filter-0.1.0.zip


Then follow the instructions for [[Installing a Filter]].
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 ==
Línia 13: Línia 13:
Enclose your code in spans like so:
Enclose your code in spans like so:


<nowiki><span syntax="langname"> 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>


=== Supported languages ===
=== Supported languages ===
Línia 26: Línia 29:
* [[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.
See the examples above. This filter is still under development so things may change.
 
* 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 ==
== Demo ==
Línia 51: Línia 47:


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.


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

Revisió del 11:12, 18 jul 2006

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:

http://geshi.org/downloads/moodle-geshi-filter-0.1.0.zip

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 like so:

[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]

Supported languages

  • asm,
  • bash,
  • cpp,
  • CSS
  • lisp
  • matlab
  • HTML
  • PHP
  • pascal
  • sql
  • xml

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

History

This filter used to use <span syntax="language">...</span> as markers for code. However this changed after conflicts with the HTMLArea editor became apparent.

See also