# -*- coding: utf-8 -*- # # Copyright (C) 2013 Yasumichi Akashoshi # All rights reserved. # # This software is licensed as described in the file COPYING, which # you should have received as part of this distribution. # from genshi.core import Markup from trac.core import * from trac.web.chrome import ITemplateProvider, add_stylesheet from trac.wiki.macros import WikiMacroBase from trac.wiki import Formatter import StringIO class AdmonitionMacro(WikiMacroBase): """Admonition""" implements(ITemplateProvider) revision = "$Rev$" url = "$URL$" def expand_macro (self, formatter, name, text, args): # Make sure data capsule is in place if not hasattr(formatter, '_admonition'): formatter._admonition = [] # Chrome add_stylesheet(formatter.req, 'admonition/admonition.css') type = 'note' # Get type if 'type' in args: if args['type'].lower() in ['note', 'warning', 'important']: type = args['type'].lower() # Build Markup html = '
\n' % type html += '
\n' % type # Convert Wiki markup to HTML, new style out = StringIO.StringIO() Formatter(self.env, formatter.context).format(text, out); html += out.getvalue() html += '
\n' html += '
\n' return html # ITemplateProvider methods def get_htdocs_dirs(self): from pkg_resources import resource_filename return [('admonition', resource_filename(__name__, 'htdocs'))] def get_templates_dirs(self): return []