Snippet Macro
Extracts a portion of code delimited by a token. This macro mimicks the behavior of the Confluence Snippet macro.Usage
#snippet(lang, id, url)
Parameters definition
| Name | Optional | Allowed values | Default value | Description |
|---|---|---|---|---|
| lang | no | String | none | Language to be used when wrapping the content in the {code} macro |
| id | no | String | none | The token id. Tokens are of the form // START SNIPPET: <id> / // END SNIPPET: <id> |
| url | no | String | none | The URL from where to get the content to display |
Example
#snippet("java", "boy", "http://svn.codehaus.org/picocontainer/java/1.x/picocontainer/trunk/container/src/test/org/picocontainer/doc/tutorial/simple/Boy.java")Result
Installation
This a Velocity macro. Since it's not bundled by default you'll have to copy/paste the following code to use it:#macro(snippet $lang $id $url)
#set($codestart = "{CODE:$lang}")
$codestart.toLowerCase()
#set ($text = $xwiki.getURLContent($url))
#set ($delimiter = "// START SNIPPET: $id")
#set ($pos1 = $xwiki.add($text.indexOf($delimiter), $delimiter.length()))
#set ($pos2 = $text.indexOf("// END SNIPPET: $id"))
$text.substring($pos1, $pos2)
#set($codeend = "{CODE}")
$codeend.toLowerCase()
#end
Version 3.1 last modified by VincentMassol on 19/06/2008 at 22:12
Comments: 0