-
A Markdown Taglet is a taglet is a class which is quite similar to the javadoc taglet, but it could use markdown or pegdown syntax.
-
The markdown taglet is always an inline taglet.
-
It's possible to define your own options.
-
The syntax itself is a bit different. You have three possibilities:
- {{tagname tag-content}}
- {%tagname tag-content%}
- {$tagname tag-content$}
This is quite simple:
-
You must extend
ch.raffael.doclets.pegdown.mdtaglet.MarkdownTagletBase
-
Provide a public default constructor
public MyTaglet() {...}
-
Define a tag name by implementing
getName()
-
and implement one of the render methods:
- either
render(List<String> arguments)
- or
renderRaw(String tagContent)
anduseArgumentValidator()
should returnfalse
.
- either
Actually these are the mandatory steps. The rest is optional.
-
createNewInstance()
: The markdown taglet framework creates a prototype instance, and tries to create for each tag within the javadoc a new instance.- the default implementation returns
this.
- If you don't override the default implementation, you are actually working on a singleton :-(.
- the default implementation returns
-
afterOptionsSet()
: After all options (see below) has been set the prototype instance could do some initialization. This method will be called only once and before anycreateNewInstance()
. -
getWhiteSpacePreserver()
: AWhiteSpacePreserver
is responsible what happens to the leading and trailing whitespaces around the actually tag.- This is useful, if you want to control the rendering. See the `GistMarkdownTaglet` as an example. - The default implementation returns `PredefinedWhiteSpacePreserver.KEEP_ALL`
-
getArgumentValidator()
: ifuseArgumentValidator()
returnstrue
, the framework splits the content of the tag into a argument list and uses theArgumentValidator
to check, if arguments are valid.- If the argument's not valid, the taglet will not applied, but marked with an appropriate error message. - There are a lot of predefined `ArgumentValidator`: `ch.raffael.doclets.pegdown.mdtaglet.argval.PredefinedArgumentValidators`. - The default implementation returns `PredefinedArgumentValidators.ZERO_OR_MORE`.
-
custom taglet options: The framework supports the possibility to customize your taglet, by using the annotation
@Option("my-option")
.- Every option could set by executing the pegdown doclet with `-mdt-my-option value` - The method must be public and have a single String parameter: `@Option("my-option1") public void setOption1(String option1) {...}`
Two steps must be done:
i. Add your taglet to the classpath (otherwise it won't be found)
ii. Register it by calling the javadoc tool with -mdtaglet the.full.path.to.your.Taglet
First step. Add an option method to your taglet. Example:
public class HelloTaglet {
private String language="EN";
@Option("hello-lang")
// or this also possible
// @Option("-mdt-hello-lang")
public void setDefaultLanguage(String language) {
this.language = language;
}
// rest ommitted for brevity
}
Second step. Call the javadoc tool (for example) with -mdt-hello-lang DE
.
i. Override useArgumentValidator()
returning false
.
ii. Override renderRaw(String tagContent)
and do what you ever want.
This is already implemented by the framework. For example:
/**
* This is my tag {{mytag hello world}}
*/
This will be split into an argument list with hello and world.
/**
* This is my tag {{mytag 'hello world'}} or {{mytag "hello world"}}
*/
In both cases this will be only one argument with of course hello world. Even the number of whitespace characters will be kept.
No. It's part of the pegdown doclet.
Yes, that's possible. example:
/**
* This is my tag {{highlight Say hi to
* - Uncle Bob
* - my wife Mary
* ...
* }}
*/
You need to use the renderRaw(String tagContent)
.
Then you will get everything inside it as a single string (including whitespace, linefeeds etc).
First you have to fork the pegdown doclet and
second add your taglet to ch.raffael.doclets.pegdown.mdtaglet.StandardTaglets
.
If you like to have it in the official version, you need to make a pull request.
Study the Hello World example.
Study the ch.raffael.doclets.pegdown.mdt.gist.GistMarkdownTaglet
and
it's test class mdtaglets.GistMarkdownTagletSpec
.