wiki:IncludeSourceMacro

Version 2 (modified by anonymous, 3 years ago) (diff)

--

Here is an idea of IncludeSourceMacro porting to 0.12 :

from genshi.core import Markup

from trac.wiki.macros import WikiMacroBase
from trac.versioncontrol import RepositoryManager

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

    Syntaxe :
    `[[IncludeSource(pathToFile)]]`

    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 node.name.endswith(".textile"):
        import textile
        content = textile.textile(content.encode('utf-8'), encoding='utf-8')

        return content