Version 1 (modified by anonymous, 6 years ago) (diff)


Here is an idea of InculdeSourceMacro porting to 0.12 :

from genshi.core import Markup

from import WikiMacroBase
from trac.versioncontrol import RepositoryManager

class IncludeSourceMacro(WikiMacroBase):
    """Include source from mean SVN repository.

    Syntaxe :

    Supports formatings :
     * Textile

    TODO :
     * Supports HTML
     * Supports repository specification
     * Supports revision giving

    revision = "$Rev$"
    url = "$URL$"

    def expand_macro(self, formatter, name, text, args):
        """Return some output that will be displayed in the Wiki content.
    if text == None:
        return "No source provided"

    repo = RepositoryManager(self.env).get_repository(None)
    node = repo.get_node(text)
    content = node.get_content().read()
    mime = node.get_content_type()
    if mime == "text/textile" or".textile"):
        import textile
        content = textile.textile(content.encode('utf-8'), encoding='utf-8')

        return content