On 25.02.2012 23:59, Benjamin Lau wrote:
Is there some way to determine whether the macro is being used inline
([[Spoiler(a spoiler)]]) vs as a preprocessor?

Yes. The `args` parameter of `expand_macro` is `Null` for inline macro syntax, but a (possibly empty) dictionary for preprocessor syntax.[1] So you could test this:
        def expand_macro(self, formatter, name, content, args):
                if args is None:
                        # [[Spoiler(a spoiler)]]
                else:
                        # {{{#!Spoiler a spoiler}}}

Alternatively, you could search for newlines in `content`:
        def expand_macro(self, formatter, name, content, args):
                if '\n' in content:
                        # multiple lines
                else:
                        # single line


Related: You could implement `is_inline`.[2] In Trac 0.13 this allows you to use inline macros in titles and other inline formatted content.

I.e. just add something like this:
        def is_inline(self, content):
                return not '\n' in content

And you can do something like this:
        == This title contains a [[Spoiler(spoiler)]]

--
Peter

[1] http://www.edgewall.org/docs/trac-trunk/html/api/trac_wiki_api.html#trac.wiki.api.IWikiMacroProvider.expand_macro [2] http://www.edgewall.org/docs/trac-trunk/html/api/trac_wiki_api.html#trac.wiki.api.IWikiMacroProvider.is_inline

--
You received this message because you are subscribed to the Google Groups "Trac 
Development" group.
To post to this group, send email to trac-dev@googlegroups.com.
To unsubscribe from this group, send email to 
trac-dev+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/trac-dev?hl=en.

Reply via email to