Changes between Version 2 and Version 3 of WikiMacros


Ignore:
Timestamp:
Aug 5, 2014, 3:59:20 PM (10 years ago)
Author:
trac
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • WikiMacros

    v2 v3  
    33[[PageOutline]]
    44
    5 Trac macros are plugins to extend the Trac engine with custom 'functions' written in Python. A macro inserts dynamic HTML data in any context supporting WikiFormatting.
     5Trac macros are plugins to extend the Trac engine with custom 'functions' written in Python. A macro inserts dynamic HTML data in any context supporting WikiFormatting. Its syntax is `[[macro-name(optional-arguments)]]`.
    66
    7 Another kind of macros are WikiProcessors. They typically deal with alternate markup formats and representation of larger blocks of information (like source code highlighting).
     7The WikiProcessors are another kind of macros. They typically deal with alternate markup formats and transformation of larger "blocks" of information (like source code highlighting). They are used for processing the multiline `{{{#!wiki-processor-name ... }}}` blocks.
    88
    99== Using Macros ==
     
    1414The list of available macros and the full help can be obtained using the !MacroList macro, as seen [#AvailableMacros below].
    1515
    16 A brief list can be obtained via ![[MacroList(*)]] or ![[?]].
     16A brief list can be obtained via `[[MacroList(*)]]` or `[[?]]`.
    1717
    18 Detailed help on a specific macro can be obtained by passing it as an argument to !MacroList, e.g. ![[MacroList(MacroList)]], or, more conveniently, by appending a question mark (?) to the macro's name, like in ![[MacroList?]].
     18Detailed help on a specific macro can be obtained by passing it as an argument to !MacroList, e.g. `[[MacroList(MacroList)]]`, or, more conveniently, by appending a question mark (`?`) to the macro's name, like in `[[MacroList?]]`.
    1919
    2020
     
    4848  }}}
    4949}}}
    50 {{{#!td style="padding-left: 2em; font-size: 80%"
    51 [[?]]
     50{{{#!td style="padding-left: 2em"
     51{{{#!html
     52<div style="font-size: 80%" class="trac-macrolist">
     53<h3><code>[[Image]]</code></h3>Embed an image in wiki-formatted text.
     54
     55The first argument is the file …
     56<h3><code>[[InterTrac]]</code></h3>Provide a list of known <a class="wiki" href="/wiki/InterTrac">InterTrac</a> prefixes.
     57<h3><code>[[InterWiki]]</code></h3>Provide a description list for the known <a class="wiki" href="/wiki/InterWiki">InterWiki</a> prefixes.
     58<h3><code>[[KnownMimeTypes]]</code></h3>List all known mime-types which can be used as <a class="wiki" href="/wiki/WikiProcessors">WikiProcessors</a>.
     59Can be …</div>
     60}}}
     61etc.
    5262}}}
    5363
     
    138148For example, when writing:
    139149{{{
    140 {{{#!HelloWorld style="polite"
     150{{{#!HelloWorld style="polite" -silent verbose
    141151<Hello World!>
    142152}}}
     
    150160One should get:
    151161{{{
    152 Hello World, text = <Hello World!> , args = {'style': u'polite'}
     162Hello World, text = <Hello World!> , args = {'style': u'polite', 'silent': False, 'verbose': True}
    153163Hello World, text = <Hello World!> , args = {}
    154164Hello World, text = <Hello World!> , args = None
     
    161171{{{
    162172#!python
    163     text = "whatever wiki markup you want, even containing other macros"
    164     # Convert Wiki markup to HTML, new style
    165     out = StringIO()
    166     Formatter(self.env, formatter.context).format(text, out)
    167     return Markup(out.getvalue())
     173from genshi.core import Markup
     174from trac.wiki.macros import WikiMacroBase
     175from trac.wiki import Formatter
     176import StringIO
     177
     178class HelloWorldMacro(WikiMacroBase):
     179        def expand_macro(self, formatter, name, text, args):
     180                text = "whatever '''wiki''' markup you want, even containing other macros"
     181                # Convert Wiki markup to HTML, new style
     182                out = StringIO.StringIO()
     183                Formatter(self.env, formatter.context).format(text, out)
     184                return Markup(out.getvalue())
    168185}}}