Created
November 29, 2012 09:56
-
-
Save wonderful-panda/4167905 to your computer and use it in GitHub Desktop.
DivHelperPlugin
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| [divhelper] | |
| div-alias.foo = class=foo | |
| span-alias.red = "style=color:red;" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # -*- coding:utf8 -*- | |
| from trac.core import * | |
| from trac.config import ConfigSection | |
| from trac.wiki import IWikiMacroProvider | |
| from trac.wiki.formatter import system_message | |
| from trac.wiki.formatter import WikiProcessor | |
| from trac.wiki.parser import parse_processor_args | |
| class DivHelperPlugin(Component): | |
| "undocumented" | |
| implements (IWikiMacroProvider) | |
| _section = ConfigSection('divhelper', 'undocumented') | |
| _prefixes = {"div": "div-alias.", "span": "span-alias."} | |
| def get_macros(self): | |
| yield "cdiv" | |
| yield "cspan" | |
| for name, value in self._section.options(): | |
| for pname, prefix in self._prefixes.items(): | |
| if name.startswith(prefix): | |
| yield pname + '_' + name[len(prefix):] | |
| def get_macro_description(self, name): | |
| return 'undocumented : %s' % name | |
| def expand_macro(self, formatter, name, content, args = None): | |
| if name in ("cdiv", "cspan"): | |
| try: | |
| clsname, content = content.split(",", 1) | |
| pname = name[1:] | |
| pargs = {"class": clsname} | |
| content = content.strip() | |
| except: | |
| return system_message("%s: invalid args (%s)" % (name, content)) | |
| else: | |
| pname, alias = name.split("_", 1) | |
| key = self._prefixes[pname] + alias | |
| pargs = parse_processor_args(self._section.get(key)) | |
| p = WikiProcessor(formatter, pname, pargs) | |
| return p.processor(content) | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| [[div_foo(あれこれ)]] | |
| [[cdiv(bar, あれこれ)]] | |
| [[span_red('''赤太字''')]] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment