wiki:CodeExampleMacro

Version 12 (modified by nuald, 4 years ago) (diff)

New parameters using style has been documented.

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. The SELECT ALL link highlights all of the code in the box to simplify the copy and paste action.

All rights reserved by Codedgers Inc.

Bugs/Feature Requests

Existing bugs and feature requests for CodeExampleMacro are here.

If you have any issues, create a new ticket.

Download

Download the zipped source from here.

Source

You can check out CodeExampleMacro from here using Subversion, or browse the source with Trac.

Example

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')]
}}}

will be rendered as:

The incorrect example:

{{{
#!CodeExample
## type = bad
#!haskell
fibs = 0 : 1 : [ a + b | a <- fibs | b <- tail fibs ]
}}}

will be rendered as:

The correct example:

{{{
#!CodeExample
## type = good
#!haskell
fibs = 0 : 1 : zipWith (+) fibs (tail fibs)
}}}

will be rendered as:

There is also support for getting sources from the repository:

{{{
#!CodeExample
## path=GPGMail/Source/GPGMailPreferences.m
## regex=".*updater\s*{"
## lines=3
#!objective-c
}}}

will be rendered as:

Parameters:

  • type - (optional) a type of the example: simple (default), good, bad
  • path - (optional) a file in the repository (using TracLinks format for source code)
  • regex - (optional) a regular expression indicates where to start an example
  • lines - (optional) number of lines to show

Recent Changes

[14039] by rjollos on 2014-07-26 02:37:54
1.2: Include images in egg and fixed links to sample screenshots. Fixes #8331.

Thanks to AllenB and ilewismsl for the patches.

[14038] by rjollos on 2014-07-26 02:37:35
Added URL to setup.py and bumped version to 1.1. Refs #9716.
[14037] by rjollos on 2014-07-26 02:37:25
Fixed title bar link when repository is specified. Fixes #9716.

Author/Contributors

Author: nuald
Maintainer: nuald
Contributors:

Attachments (7)

Download all attachments as: .zip