Ticket #5654: tracpygments-options.diff
| File tracpygments-options.diff, 1.7 KB (added by thatch, 5 years ago) |
|---|
-
__init__.py
60 60 to override the default quality ratio used by the 61 61 Pygments render.""") 62 62 63 pygments_options = ListOption('mimeviewer', 'pygments_options', 64 '', doc= 65 """List of options to be passed to lexers. 66 67 For each, a tuple `mode:option` has to be specified, 68 for example `php:startinline=1`. To specify more than 69 one option, simply repeat the mode in the style, 70 `php:a=1,php:b=2` 71 """) 72 63 73 expand_tabs = True 64 74 returns_source = True 65 75 … … 218 228 Mimeview(self.env).configured_modes_mapping('pygments') 219 229 ) 220 230 231 self._options = {} 232 for t, opt in [x.split(':', 1) for x in self.pygments_options]: 233 opts = self._options.get(t) 234 if not opts: 235 opts = {} 236 self._options[t] = opts 237 key, value = opt.split('=', 1) 238 opts[str(key)] = value 239 240 221 241 def _highlight(self, language, content, annotate): 242 self.log.debug("Pygments renderering for language=%s" % language) 222 243 formatter = HtmlFormatter(cssclass=not annotate and 'code' or '') 223 html = pygments.highlight(content, get_lexer_by_name(language), 244 opts = self._options.get(language, {}) 245 opts['stripnl'] = False 246 lexer = get_lexer_by_name(language, **opts) 247 html = pygments.highlight(content, lexer, 224 248 formatter).rstrip('\n') 225 249 if annotate: 226 250 return html[len('<div><pre>'):-len('</pre></div>')].splitlines()
