| 70 | | def trac(href, name, arguments, options, content, lineno, |
| | 76 | |
| | 77 | def trac_get_reference(env, rawtext, text): |
| | 78 | for (pattern, function) in LINKS: |
| | 79 | m = pattern.match(text) |
| | 80 | if m: |
| | 81 | g = filter(None, m.groups()) |
| | 82 | missing = False |
| | 83 | if pattern == WIKI_LINK: |
| | 84 | if not (env._wiki_pages.has_key(g[0])): |
| | 85 | missing = True |
| | 86 | text = text + "?" |
| | 87 | uri = function(env.href, g) |
| | 88 | reference = nodes.reference(rawtext, text) |
| | 89 | reference['refuri']= uri |
| | 90 | if missing: |
| | 91 | reference.set_class('missing') |
| | 92 | return reference |
| | 93 | return None |
| | 94 | |
| | 95 | def trac(env, name, arguments, options, content, lineno, |
| 93 | | for (pattern, function) in LINKS: |
| 94 | | m = pattern.match(arguments[0]) |
| 95 | | if m: |
| 96 | | text = arguments[int(len(arguments) == 2)] |
| 97 | | g = filter(None, m.groups()) |
| 98 | | uri = function(href, g) |
| 99 | | reference = nodes.reference(block_text, text) |
| 100 | | reference['refuri']= uri |
| 101 | | return reference |
| 102 | | |
| | 118 | text = arguments[int(len(arguments) == 2)] |
| | 119 | reference = trac_get_reference(env, block_text, text) |
| | 120 | if reference: |
| | 121 | return reference |
| 111 | | def trac_role(href, name, rawtext, text, lineno): |
| 112 | | for (pattern, function) in LINKS: |
| 113 | | m = pattern.match(text) |
| 114 | | if m: |
| 115 | | g = filter(None, m.groups()) |
| 116 | | uri = function(href, g) |
| 117 | | return [nodes.reference(rawtext, text, refuri=uri)], [] |
| | 130 | |
| | 131 | def trac_role(env, name, rawtext, text, lineno, inliner, options={}, content=[]): |
| | 132 | reference = trac_get_reference(env, rawtext, text) |
| | 133 | if reference: |
| | 134 | return [reference], [] |
| 129 | | def do_trac_role(name, rawtext, text, lineno): |
| 130 | | return trac_role(env.href, name, rawtext, text, lineno) |
| | 147 | def do_trac_role(name, rawtext, text, lineno, inliner, options={}, content=[]): |
| | 148 | return trac_role(env, name, rawtext, text, lineno, inliner, options, content) |
| 139 | | _inliner = rst.states.Inliner(roles = local_roles) |
| | 157 | # The code_block could is taken from the leo plugin rst2 |
| | 158 | def code_block(name,arguments,options,content,lineno,content_offset,block_text,state,state_machine): |
| | 159 | |
| | 160 | """Create a code-block directive for docutils. |
| | 161 | |
| | 162 | Usage: .. code-block:: language |
| | 163 | |
| | 164 | If the language can be syntax highlighted it will be.""" |
| | 165 | |
| | 166 | |
| | 167 | |
| | 168 | from trac.WikiFormatter import Formatter |
| | 169 | |
| | 170 | language = arguments[0] |
| | 171 | |
| | 172 | code_processor = None |
| | 173 | if Formatter.builtin_processors.has_key(language): |
| | 174 | code_processor = Formatter.builtin_processors[language] |
| | 175 | else: |
| | 176 | code_processor = Formatter.builtin_processors['default'] |
| | 177 | |
| | 178 | |
| | 179 | html = code_processor(hdf, '\n'.join(content), env) |
| | 180 | raw = nodes.raw('',html, format='html') #(self, rawsource='', text='', *children, **attributes): |
| | 181 | return [raw] |
| | 182 | |
| | 183 | # These are documented at http://docutils.sourceforge.net/spec/howto/rst-directives.html. |
| | 184 | code_block.arguments = ( |
| | 185 | 1, # Number of required arguments. |
| | 186 | 0, # Number of optional arguments. |
| | 187 | 0) # True if final argument may contain whitespace. |
| | 188 | |
| | 189 | |
| | 190 | # A mapping from option name to conversion function. |
| | 191 | code_block.options = { |
| | 192 | 'language' : |
| | 193 | rst.directives.unchanged # Return the text argument, unchanged |
| | 194 | } |
| | 195 | code_block.content = 1 # True if content is allowed. |
| | 196 | # Register the directive with docutils. |
| | 197 | rst.directives.register_directive('code-block',code_block) |
| | 198 | |
| | 199 | |
| | 200 | |
| | 201 | _inliner = rst.states.Inliner() |