Changes between Version 51 and Version 52 of WikiMacros
- Timestamp:
- Aug 9, 2017, 9:20:03 AM (7 years ago)
Legend:
- Unmodified
- Added
- Removed
- Modified
-
WikiMacros
v51 v52 174 174 Note 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`). 175 175 176 You can also recursively use a wiki Formatter (`from trac.wiki import Formatter`)to process the `text` as wiki markup:176 You can also recursively use a wiki formatter to process the `text` as wiki markup: 177 177 178 178 {{{#!python 179 from trac. util.html import Markup179 from trac.wiki.formatter import format_to_html 180 180 from trac.wiki.macros import WikiMacroBase 181 from trac.wiki import Formatter182 import StringIO183 181 184 182 class HelloWorldMacro(WikiMacroBase): 185 183 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 191 188 }}}