Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: Migrated to Confluence 4.0

Guide to Doxia Macros

Warning
titleOut of Date

This page is out-of-date. Please see the Doxia Macros Guide.

The Doxia Core module includes the Echo and Snippet macros, and you can create your own.

Macros are Plexus components with a role of org.apache.macro.doxia.macro.Macro.

The role-hint is the macro name.

For example:

Code Block
/**
 * @plexus.component role="org.apache.maven.doxia.macro.Macro"
 * role-hint="echo"
 */
public class EchoMacro extends AbstractMacro
{
   public void execute( Sink sink, MacroRequest request ) { ... }
}

is called with

Code Block
%{echo|param=value|param2=value2}

and will output

No Format
  param ---> value
  param2 ---> value2

(The echo macro simply prints out the key and value of any parameters that you supply.)

Note that macros must not be indented in your apt source document.

In the execute method, TODO

The following plugin config can be used to generate the Plexus component.xml file for the module containing your macro:

Code Block
<build>
          ...
          <plugins>
            <plugin>
              <groupId>org.codehaus.plexus</groupId>
              <artifactId>plexus-maven-plugin</artifactId>
              <executions>
                <execution>
                  <goals>
                    <goal>descriptor</goal>
                  </goals>
                </execution>
              </executions>
            </plugin>
          ...
          </plugins>
        ...
        </build>

Using Doxia Macros by samples

Snippet

For instance, in apt file:

Code Block
%{snippet|id=superpom|url=http://svn.apache.org/repos/asf/maven/components/trunk/maven-project/src/main/resources/org/apache/maven/project/pom-4.0.0.xml}

And in xdoc file:

Code Block
<macro name="snippet" id="superpom" url="http://svn.apache.org/repos/asf/maven/components/trunk/maven-project/src/main/resources/org/apache/maven/project/pom-4.0.0.xml"/>

Table Of Content (toc)

For instance, in APT file:

Code Block
%{toc|section=2|fromDepth=1|toDepth=2}

And in Xdoc file:

Code Block
<macro name="toc" section="1" fromDepth="1" toDepth="2"/>

From Javadoc:

section

Display the specificated section number or all sections if 0 (in this case, other paramaters are ignored).
Positive int, not mandatory, 0 by default.

fromDepth

Display the depth starting for the given section number.
Positive int, not mandatory, 0 by default.

toDepth

Display the depth ending for the given section number.
Positive int, not mandatory, 5 by default.