Pygments & syntax highlighting

69 views
Skip to first unread message

Emmanuel Blot

unread,
Aug 16, 2012, 6:11:31 AM8/16/12
to trac-...@googlegroups.com
Hi,

I'm not sure how to add file type that Pygments supports natively, but
that Trac does not recognize.

For example, CMake files have been supported by Pygments for a long
time (since 1.2), but Trac does not manage them.

It seems the way to go (from
http://trac.edgewall.org/wiki/TracIni#mimeviewer-section) is to add
CMake type to the mime_map option.

I've added "text/x-cmake:cmake" and now the syntax highlighter works
with "#!cmake" in quoted blocks. However, Trac file browser does not
highlight CMakeLists.txt files. I've added
"text/x-cmake:CMakeLists.txt" to the mime_map option, but it does not
help.

1. Specific question: How to specify to Trac that "CMakeLists.txt"
files should be highlighted
2. Generic question: How to tell Trac to defer all highlighting
decisions to Pygments, which already knows about all supported types,
rather than letting Trac performs the mapping on its own - is it even
possible?

TIA,
Manu

Christian Boos

unread,
Aug 16, 2012, 7:45:07 AM8/16/12
to trac-...@googlegroups.com
On 8/16/2012 12:11 PM, Emmanuel Blot wrote:
> Hi,
>
> I'm not sure how to add file type that Pygments supports natively, but
> that Trac does not recognize.
>
> For example, CMake files have been supported by Pygments for a long
> time (since 1.2), but Trac does not manage them.
>
> It seems the way to go (from
> http://trac.edgewall.org/wiki/TracIni#mimeviewer-section) is to add
> CMake type to the mime_map option.
>
> I've added "text/x-cmake:cmake" and now the syntax highlighter works
> with "#!cmake" in quoted blocks. However, Trac file browser does not
> highlight CMakeLists.txt files. I've added
> "text/x-cmake:CMakeLists.txt" to the mime_map option, but it does not
> help.
>
> 1. Specific question: How to specify to Trac that "CMakeLists.txt"
> files should be highlighted

I believe we only look for the suffix, not for the full name with
fnmatch. See get_mimetype() in trac/mimeview/api.py.

> 2. Generic question: How to tell Trac to defer all highlighting
> decisions to Pygments, which already knows about all supported types,
> rather than letting Trac performs the mapping on its own - is it even
> possible?
>

No. This is #5533.

So basically the only "solution" you have for now short of implementing
#5533, is to do a `svn pset svn:mime-type text/x-cmake` on your CMake
files in the repository.

Cheers,

-- Christian

Emmanuel Blot

unread,
Aug 16, 2012, 11:53:31 AM8/16/12
to trac-...@googlegroups.com
Hi Christian,

> No. This is #5533.
Ok ;-)

> So basically the only "solution" you have for now short of implementing
> #5533, is to do a `svn pset svn:mime-type text/x-cmake` on your CMake files
> in the repository.
Ok. I don't think it worth dealing with so many changes. I can leave without.

Thanks for your help,
Manu
Reply all
Reply to author
Forward
0 new messages