Edgewall Software

Changes between Version 51 and Version 52 of WikiMacros


Ignore:
Timestamp:
Aug 9, 2017, 9:20:03 AM (7 years ago)
Author:
Ryan J Ollos
Comment:

Use appropriate helper function.

Legend:

Unmodified
Added
Removed
Modified
  • WikiMacros

    v51 v52  
    174174Note that the return value of `expand_macro` is '''not''' HTML escaped. Depending on the expected result, you should escape it yourself (using `return Markup.escape(result)`) or, if this is indeed HTML, wrap it in a Markup object: `return Markup(result)` (`from trac.util.html import Markup`).
    175175
    176 You can also recursively use a wiki Formatter (`from trac.wiki import Formatter`) to process the `text` as wiki markup:
     176You can also recursively use a wiki formatter to process the `text` as wiki markup:
    177177
    178178{{{#!python
    179 from trac.util.html import Markup
     179from trac.wiki.formatter import format_to_html
    180180from trac.wiki.macros import WikiMacroBase
    181 from trac.wiki import Formatter
    182 import StringIO
    183181
    184182class HelloWorldMacro(WikiMacroBase):
    185183    def expand_macro(self, formatter, name, text, args):
    186         text = "whatever '''wiki''' markup you want, even containing other macros"
    187         # Convert Wiki markup to HTML, new style
    188         out = StringIO.StringIO()
    189         Formatter(self.env, formatter.context).format(text, out)
    190         return Markup(out.getvalue())
     184        markup = "any '''wiki''' markup you want, even containing other macros"
     185        # Convert Wiki markup to HTML
     186        return format_to_html(self.env, formatter.context, markup)
     187
    191188}}}