This server will be upgraded at 3pm Sydney time on December 3rd (December 2nd, 8pm PST) and will be down for up to 30 minutes.

Snippet Plugin

Name Snippet Plugin
Vendor Atlassian Software Systems (Website)
Authors Don Brown, Patrick Lightbody
Homepage http://confluence.atlassian.com/display/CONFEXT/Snippet+Plugin
Issue Management n/a
Continuous Integration n/a
Categories Content Macros
Most Recent Version 2.0.2
Availability Confluence v2.2.1 to v2.10
State Stable
Support Unsupported Plugins
License Freeware / Open Source (BSD)
Price Free
Release Docs http://confluence.atlassian.com/display/CONFEXT/Snippet+Plugin
Java API Docs n/a
Download Source http://svn.atlassian.com/svn/public/contrib/confluence/snippet-plugin/tags/2.0.2
Download JAR snippet-2.0.2.jar

What is it?

A Confluence plugin to retrieve and display a snippet of text from a remote URL (e.g., Subversion).
The content will be trimmed down to the content found between some special tags. This is very handy for documentation that includes code. The code can be in Subversion (whatever build system is used will make sure it builds properly) and the URL can be a Subversion URL. (In case of ViewCVS the URL should point to the download URL of a file). The content is cached for configurable period, defaulting to one hour, in order to improve performance. The snippet is also unindented to remove excess space.

This can ensure that code examples in your documentation are kept up-to-date since they are sourced from the original code, thus preserving ideas put forth in LiterateProgramming.

The original version was spawned at codehaus (written by those two legendary maestros of code - Jon Tirsen and Aslak Hellesoy) and the code for it still lives there. A later version, 1.0, can be found at Snippet Macro Library V1.

Features

  • Configurable snippet url prefixes and settings via a plugin configuration page
  • Caching of snippets to improve performance
  • Snippet errors are saved per space and displayed in the Space Administration section
  • Ability to clear cache and saved snippet errors

Snippet Macro

Usage

{snippet:id=<snippetId>|url=<sourceURL>|lang=<language>|linenumbers=<true|false>|javadoc=<true|false>}

Parameters

Parameter Required Values Default Notes
id   Any string all The id of the snippet in the URL content
url Any string, must start with a configured prefix   The location of the content containing the snippet
lang   Any language supported by the code macro   If present, will wrap the content in {code:lang}
linenumbers   true, false false If true, will add line numbers
javadoc   true, false false If true, performs extra processing like removing starting * and space characters, escaping XML, and cleaning out {@link} tags

Example

URL/snippet content
this
// START SNIPPET: something
macro
// START SNIPPET: somethingElse
is
// END SNIPPET: somethingElse
very
// END SNIPPET: something
cool
Macro usage
{snippet:lang=java|id=something|linenumbers=true|url=http://some/url/to/viewcvs}

This will give the following content:

{code:java}
1. macro
2. is
3. very
{code}

Administration

Administrative tasks are available for the members of the confluence-administrators group and space administrators:

Confluence Administrators
  • Change plugin settings including cache expiration and snippet wrappers
  • Add or remove allowed snippet url prefixes
  • Flush the snippet cache
  • Clear all snippet errors
Space Administrators
  • View snippet errors
  • Clear snippet errors for their space

Version History

Version Date Author Notes
2.0 Dec 15, 2006 Don Brown Updated for Confluence 2.2, added administration and error collection
1.0 Jun 22, 2005 David Loeng Updated for Confluence 1.4
0.4 Dec 15, 2004 RefuX Zanzeenbarr Updated for Confluence 1.3
0.3 Jul 08, 2004 Nick Sieger Initial release

Issue Tracking


Screenshots


Labels

plugin plugin Delete
Enter labels to add to this page:
Please wait 
Looking for a label? Just start typing.
  1. Aug 30, 2007

    Matt Raible says:

    This plugin doesn't seem to work with Confluence 2.5.4. I've configured it with ...

    This plugin doesn't seem to work with Confluence 2.5.4. I've configured it with a prefix of "demos:" pointing to http://appfuse-demos.googlecode.com/svn/trunk/. When I use the following snippet, it results in the following error.

    {snippet:lang=java|id=id|url=demos:tutorial-hibernate/src/main/java/org/appfuse/tutorial/model/Person.java}
    

    Error formatting macro: snippet: java.lang.IllegalArgumentException: Invalid url: must begin with a configured prefix.

    If I google for Invalid url: must begin with a configured prefix, I see a lot of sites with this error and non-rendered content.

    Is this plugin stable enough to use reliably?

    Thanks,

    Matt

  2. Jan 22, 2008

    Christian Blavier says:

    Hi, is this plugin still maintained ? I mean in case of future upgrades of Con...

    Hi,

    is this plugin still maintained ?

    I mean in case of future upgrades of Confluence, do you ensure that the snippet plugin will still work ?

    Why isn't it available in plugin repository ? 

    Thanks

  3. Feb 26, 2008

    Hernan Cunico says:

    Related to the prev comment about future support. How about adding extra display...

    Related to the prev comment about future support. How about adding extra display controls like title, borderStyle and the others supported by

    Cheers!

    1. Feb 26, 2008

      Choy Li Tham says:

      Hi Hernan, Unfortunately, this feature is not provided currently. However, if y...

      Hi Hernan,

      Unfortunately, this feature is not provided currently. However, if you are keen on this feature, you may want to raise a feature request at the Snippet Plugin Issue Tracker to truly reflect your requirement.

      Regards,
      Choy Li

  4. Jul 17

    Dhana Lakshmi Marothu says:

    If I want to use {snippet} macro, do I need to cofigure the macro first? I mean ...

    If I want to use {snippet} macro, do I need to cofigure the macro first? I mean to ask do I need to add a URL under "Add a URL prefix"? I tried the macro with the below syntax. it did not work .

     I have used below syntax and we are using confluence 2.6.2:

    {snippet:lang=java|id=testing|linenumbers=true|url=http://svrplumtreeapps/travelform/sendmail.aspx.cs\}

    Below error I am getting. 

    Error formatting macro: snippet: java.lang.IllegalArgumentException: Invalid url: must begin with a configured prefix.
    Please help!

    1. Jul 21

      Dhana Lakshmi Marothu says:

      Any body can reply who have used already this macro!

      Any body can reply who have used already this macro!

  5. Oct 16

    Knut Wannheden says:

    You have to configure the plugin and add the corresponding prefix. Example: Add ...

    You have to configure the plugin and add the corresponding prefix. Example: Add the prefix "xfire" for the URL "http://svn.codehaus.org/xfire/trunk/xfire/" and then add this to a page:

    {snippet:id=uthp|lang=xml|url=xfire/examples/ws-security/src/main/META-INF/xfire/services.xml}