Applying Formatters
MoinMoin developers recommend that you use a Formatter to format output from your Macro, Processor, or Parser - see MoinDev/PluginConcept.
They made Formatters so that you only have to write output code once. That is, you don't have to write output code for HTML, and then XML, and then plain text.
Macro Example
Formatters are very simple to use:
1 def execute(macro, args):
2 result = []
3 result.append(macro.formatter.paragraph(1))
4 result.append(macro.formatter.text("This text appears inside of a macro."))
5 result.append(macro.formatter.text("No to escape text like </html> and <p>."))
6 result.append(macro.formatter.paragraph(0))
7 return "".join(result)
If you make many macro.formatter calls, you can shorten it:
Keys to Using Formatters
Know where to find your formatter, and know what it can do for you.
output from: |
formatter at: |
Macro |
macro.formatter parameter |
Processor |
formatter parameter |
Parser |
self.formatter |
To find everything a formatter can do, read the base formatter class: