Edgewall Software
Modify

Ticket #5654 (new enhancement)

Opened 5 years ago

Last modified 2 years ago

pygments_renderer should support passing options to lexers

Reported by: thatch Owned by: thatch
Priority: normal Milestone: next-major-0.1X
Component: rendering Version: devel
Severity: normal Keywords: pygments review
Cc:
Release Notes:
API 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

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

Download all attachments as: .zip

Change History

Changed 5 years ago by thatch

First version, against r5537 in 0.11-dev

Changed 5 years ago by thatch

First version, against r2367 for tracpygments

comment:1 Changed 5 years ago by bpat1434

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

comment:2 Changed 3 years ago by cboos

  • Milestone changed from 0.11-retriage to 0.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 Changed 3 years ago by thatch

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 Changed 2 years ago by rblank

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

comment:5 Changed 2 years ago by cboos

  • Component changed from version control/browser to rendering
  • Milestone changed from 0.12 to next-major-0.1X
  • Type changed from defect to enhancement

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

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

comment:6 Changed 2 years ago by 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).

View

Add a comment

Modify Ticket

Change Properties
<Author field>
Action
as new
as The resolution will be set. Next status will be 'closed'
to The owner will be changed from thatch. Next status will be 'new'
The owner will be changed from thatch to anonymous. Next status will be 'assigned'
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.