Edgewall Software
Modify

Opened 17 years ago

Closed 9 years ago

Last modified 9 years ago

#5654 closed enhancement (fixed)

pygments_renderer should support passing options to lexers

Reported by: Tim Hatch Owned by: Ryan J Ollos
Priority: normal Milestone: 1.2
Component: rendering Version: devel
Severity: normal Keywords: pygments
Cc: Branch:
Release Notes:

Pygments lexer options can be specified as WikiProcessor arguments and defaults can be set in the environment configuration.

API Changes:
Internal Changes:

Description

I decided to split this out of #5613 because that was originally about allowing short names as wiki processors. Someone brought this up on IRC as well today, so I decided to give it a shot. I'm thinking the main place to set options should be in trac.ini, but I'd like more input (do we need a WebAdmin page for them? a way to set them as part of a wiki processor would also be great, I think, especially in the case of 'startinline' for php. I'm going to attach a first implementation for 0.11-dev, followed by an adaptation for 0.10's tracpygments.

I would like feedback, particularly on whether this is something other people are interested in, and whether it should be specified somehow for wiki processors too.

Attachments (2)

pygments-options.diff (1.5 KB ) - added by Tim Hatch 17 years ago.
First version, against r5537 in 0.11-dev
tracpygments-options.diff (1.7 KB ) - added by Tim Hatch 17 years ago.
First version, against r2367 for tracpygments

Download all attachments as: .zip

Change History (13)

by Tim Hatch, 17 years ago

Attachment: pygments-options.diff added

First version, against r5537 in 0.11-dev

by Tim Hatch, 17 years ago

Attachment: tracpygments-options.diff added

First version, against r2367 for tracpygments

comment:1 by bpat1434, 17 years ago

I'm all for this; however, trac.ini might get bloated with this. Perhaps the ability to create a new lexer.ini file in the conf directory (or the trac root for global configurations) which holds the lexer options. Something along the lines of:

lexer.csharp.unicodelevel = basic
lexer.delphi.turbopascal = disabled
lexer.php.startinline = enabled
lexer.php.disabledmodules = stripos,get_func_args,preg_match
lexer.rst.handlecodeblocks = disabled
Last edited 9 years ago by Ryan J Ollos (previous) (diff)

comment:2 by Christian Boos, 16 years ago

Milestone: 0.11-retriage0.12

Tim, how is this now handled at the Pygments level, is there a way to setup an .ini file with the options there?

Also, I think it would be nice to be able to pass the options in code blocks (e.g. #!cs lexer.csharp.unicodelevel=basic).

comment:3 by Tim Hatch, 16 years ago

There's no current method for setting up Pygments global settings, they need to be passed to the instantiation as these patches show. I'm against having a new lexer ini, but recognize that having a [mimeviewer] pygments_options can get unwieldy for lots of options.

How about something like this (basically removing the lexer. prefix and placing it in the main trac.ini):

[pygments_options]
*.stripnl = false
csharp.unicodelevel = basic
delphi.turbopascal = disabled
php.startinline = enabled
php.disabledmodules = stripos,get_func_args,preg_match
rst.handlecodeblocks = disabled

The only thing this doesn't satisfy is that some case normalization will need to be done on the lexer aliases used as ini keys. Putting each option in a dedicated line allows commas in them (my listoption solution above didn't). I'm also +1 on having a way to set them for code blocks (the real case where this shines is whether php starts inline or not).

comment:4 by Remy Blank, 15 years ago

The idea in comment:3 looks nice. Any chance to get this into 0.12?

comment:5 by Christian Boos, 15 years ago

Component: version control/browserrendering
Milestone: 0.12next-major-0.1X
Type: defectenhancement

A [pygments] section would indeed be better than a [mimeviewer] pygments_options option.

Feel free to move back when there's a patch.

Last edited 9 years ago by Ryan J Ollos (previous) (diff)

comment:6 by jappie@…, 15 years ago

I'd also like the ability to pass options in code-blocks. I'd prefer the following syntax:

#!php startinline=true

Because we define a code-block for the processor php, I see no need to explicitly state it again (like #!php lexer.php.startinline=true or #!php php.startinline=true).

comment:7 by Ryan J Ollos, 9 years ago

Owner: Tim Hatch removed

comment:8 by Ryan J Ollos, 9 years ago

#1932 closed as a duplicate. The request in #1932 will be satisfied by setting the startsinline option of PhpLexer.

in reply to:  6 comment:9 by Ryan J Ollos, 9 years ago

Replying to jappie@…:

I'd also like the ability to pass options in code-blocks. I'd prefer the following syntax:

#!php startinline=true

Because we define a code-block for the processor php, I see no need to explicitly state it again (like #!php lexer.php.startinline=true or #!php php.startinline=true).

In Trac, MIME Type WikiProcessors support some keyword arguments that are known by formatter.py: lineno, marks, id. However, there doesn't seem to be a way for Trac to know the options supported by the Lexers. The Lexer classes don't declare the valid options. Instances of the Lexer classes will consume valid options as keyword arguments and ignore invalid options.

The only way I can see to allow Pygments Lexer options to be used as keyword arguments for MIME WikiProcessor is to consider all unknown keyword arguments to be lexer options. I think that is probably okay though since the Lexers will just ignore any unknown options. We could also see if Pygments is willing to consider an enhancement in which they specify the valid option names as a class attribute.

Last edited 9 years ago by Ryan J Ollos (previous) (diff)

comment:10 by Ryan J Ollos, 9 years ago

Keywords: review removed
Milestone: next-major-releases1.2
Owner: set to Ryan J Ollos
Status: newassigned

Proposed changes in log:rjollos.git:t5654_pygments_options. I'll add tests before committing.

DONE Add documentation for pygments-lexer options to 1.1/TracSyntaxColoring.

Last edited 9 years ago by Ryan J Ollos (previous) (diff)

comment:11 by Ryan J Ollos, 9 years ago

Release Notes: modified (diff)
Resolution: fixed
Status: assignedclosed

Committed to trunk in [14207:14208]. Edited 1.1/TracSyntaxColoring@5.

Modify Ticket

Change Properties
Set your email in Preferences
Action
as closed The owner will remain Ryan J Ollos.
The resolution will be deleted. Next status will be 'reopened'.
to The owner will be changed from Ryan J Ollos to the specified user.

Add Comment


E-mail address and name can be saved in the Preferences .
 
Note: See TracTickets for help on using tickets.