Contents
Code example box with syntax highlighting
Description
The CodeExampleMacro renders a code example box that supports syntax highlighting. It support three types of examples: simple, correct, and incorrect.
Features:
- The SELECT ALL link highlights all of the code in the box to simplify the copy and paste action.
- A mouse click on the header (title) will show or hide the code block.
- Code from the repository can be displayed using TracLinks syntax. The multiple repository configuration (Trac >= 0.12) is supported.
All rights reserved by Codedgers Inc.
Usage
- Inside a wiki area you can invoke the #!CodeExample wiki processor to render a special formatted box containing specified source code, as shown and exemplified down:
{{{ #!CodeExample ## parameter = value .... ## parameter = value #!language ...code... }}}
- Where ## parameter = value can be one or many from:
Argument | Version | Required (R) Optional (O) | Description | Default |
## type | O | A type of box example: simple, good, bad * Example: ## type = bad | simple | |
## title | O | The title of the example. * Example: ## title = Source from repository A | If ## type = simple then EXAMPLE: If ## type = good then CORRECT EXAMPLE: If ## type = bad then INCORRECT EXAMPLE: | |
## path | O | A file in the repository (using TracLinks format for source code) * Example: ## path = GPGMail/Source/GPGMailPreferences.m | None | |
## repo | O | Repository to use (Trac 0.12 and upper only). * Example: ## repo = T.B.D. | None | |
## regex | O | A regular expression indicates where to start an example. * Example: ## regex = ".*updater\s*{" | None | |
## lines | O | Number of lines to show. * Example: ## lines = 3 | None | |
#!language | O | Syntax highlighter. language is any supported by Trac. See TracSyntaxColoring. * Example: #!python | trac |
- The simple example:
{{{ #!CodeExample #!python @staticmethod def get_templates_dirs(): """ Notify Trac about templates dir. """ from pkg_resources import resource_filename return [resource_filename(__name__, 'templates')] }}}
- The incorrect example:
{{{ #!CodeExample ## type = bad #!haskell fibs = 0 : 1 : [ a + b | a <- fibs | b <- tail fibs ] }}}
- The correct example:
{{{ #!CodeExample ## type = good #!haskell fibs = 0 : 1 : zipWith (+) fibs (tail fibs) }}}
- There is also support for getting sources from the repository:
{{{ #!CodeExample ## path=GPGMail/Source/GPGMailPreferences.m ## regex=".*updater\s*{" ## lines=3 #!objective-c }}}
Installation
- Install plugin globally:
- with easy_install:
$ [sudo] easy_install https://trac-hacks.org/svn/codeexamplemacro
- [sudo] is optional case you already have enough authority to modify your server.
- You might be required to select a specific tag, branch. Defaults to select from trunk
- with easy_install:
- Enable this component by updating TracIni file as follows:
[components] codeexample.code_example_processor.* = enabled
- Restart web server on command line:
$ [sudo] /etc/init.d/apache2 restart
- [sudo] is optional case you already have enough authority to modify your server.
- [sudo] is optional case you already have enough authority to modify your server.
- Test if this component is working properly.
- If the plugin is installed correct, the example shown in the #Usage section on this page should be displayed.
- If the plugin is installed correct, the example shown in the #Usage section on this page should be displayed.
Bugs/Feature Requests
Existing bugs and feature requests for CodeExampleMacro.
If you have any issues, create a new ticket.
Source & Download
You can check out CodeExampleMacro using Subversion, or browse the source with Trac, or download the zipped source.
Recent Changes
[11775] by rjollos on 07/25/12 09:01:47
Part of [11766].
[11766] by rjollos on 07/24/12 06:33:37
Renamed 0.11 directory to trunk.
[10843] by rjollos on 10/27/11 08:17:57
Adding configuration file that results in svn revision info being added to the egg file.
[10842] by rjollos on 10/27/11 08:04:27
Fixes #8890: Fixed module name in setup.py.
Author/Contributors
Attachments
- example.png (15.8 kB) -
The simple example image.
, added by nuald on 05/22/09 08:56:33. - correct_example.png (12.9 kB) -
The correct example image.
, added by nuald on 05/22/09 08:57:41. - incorrect_example.png (8.9 kB) -
The incorrect example image.
, added by nuald on 05/22/09 08:58:08. - example1.png (23.2 kB) - added by nuald on 09/29/10 08:48:17.
- example2.png (20.1 kB) - added by nuald on 09/29/10 08:48:53.
- example3.png (25.9 kB) - added by nuald on 09/29/10 08:49:11.
- example4.png (15.0 kB) - added by nuald on 09/29/10 08:49:28.