Code Macro
Last modified by Vincent Massol on 2017/07/07 09:26
![]() | Used to highlight code |
Type | JAR |
Developed by | |
Rating | |
License | GNU Lesser General Public License 2.1 |
Bundled With | XWiki Enterprise |
Table of contents
Description
See http://pygments.org/languages/ for the list of all supported languages. If you have a hard time finding the right id for the language you can look at http://pygments.org/docs/lexers/#lexers-for-php-and-related-languages.
Usage
{{code language=<providedlanguage>}}
... code here...
{{/code}}
... code here...
{{/code}}
Parameters definition
Name | Optional | Allowed values | Default value | Description |
---|---|---|---|---|
language | yes | a string | the macro tries to determine the syntax | the language identifier of the provided code snippet. If no language identifier is specified then the macro will try to determine the syntax. To avoid highlight you can use "none" language identifier. |
This macro also support all Box Macro parameters.
Configuration
It's possible to set some configuration for this macro in the xwiki.properties file:
Name | Optional | Allowed values | Default value | Description |
---|---|---|---|---|
rendering.macro.code.pygments.style (since 2.4M1) | yes | a string | default | the name of the Pygments style to use. See http://pygments.org/docs/styles/ for more about styles. |
Example:
rendering.macro.code.pygments.style=vs
Adding new languages
Anyone can add a new language support by:
- adding a XWiki java component: implementing HighlightParser interface component. See Component Module for more details on how to write component for the new XWiki 2.0 architecture
- the default org.xwiki.rendering.parser.HighlightParser is based on Pygments so the best for both projects is probably to provide a new syntax parser to Pygments project. See http://pygments.org/contribute/.
Example
{{code language="html"}}
<html>
<head>Cool!</head>
</html>
{{/code}}
<html>
<head>Cool!</head>
</html>
{{/code}}
Result
<html>
<head>Cool!</head>
</html>
<head>Cool!</head>
</html>