Specify syntax highlighting per file

Issue #3049 resolved
Former user created an issue

Can I manually specify syntax highlighting per file? Sometimes it's simply impossible to determine the kind of file just by the filename or by a quick inspection of it (e.g. is .h C or C++, is .m Matlab or Octave....) so it would help if I could manually override it for when Pygments gets it wrong.

Now that my Octave highlighting patches have gotten accepted into Pygments, I would like to be able to use them on bb. :-)

Comments (9)

  1. David Chambers

    This isn't currently possible. We've discussed the possibility of taking into account the repository's language setting when determining which lexer to use. Would this help in your situation?

  2. Anonymous

    Perhaps, if I can specify multiple languages per project. But I do think I will need per-file granularity. For example, files that have no filename extension. How would those be handled?

  3. Anonymous

    Also, where's your source so I can start looking into how to help you implement this or something like it?

  4. Dylan Etkin

    Hi Jordi,

    I am afraid that the source for Bitbucket is closed source.

    We do try to smartly determine the lexer to use for individual source files. We try to figure it out based on the file extension and if that is inconclusive we try to let Pygments guess the source type by passing it the first 1k of the file.

    The problem with letting a user specify a lexer for an individual file is that you need to store meta-data on the file and I am not really sure how we could make the UI/UX nice for that feature.



  5. Anonymous

    Oh, bitbucket is non-free? When do you expect to remedy this? How can I help?

    I think having a hideable drop down that says "specify preferred syntax highlighting mapping" both in the project's page and at a per-file overload is doable. Or just hideable fields in the project admin page that say, "map this file extension to this highlighting from this drop down".

    What do you think?

  6. Dylan Etkin

    Hi Jordi,

    We don't plan on opening the source for Bitbucket. There are portions of codebase that we will likely open source (libraries that could be useful to the python community) but Bitbucket is a comercial product.

    Your suggestion about mapping file extensions could work, seems like it would be a bit tedious if you were to do it for every repo. I guess the real question is what files are not highlighting and why does pygments not know about those files extensions and why is pygments not able to recognise the code from the snippet?



  7. Adam Gamble

    Still doesn't seem to be intuitive, or "smart"; e.g. even with the project language set to "Perl", & first line of a file: #!/usr/bin/perl

    Pygments doesn't make the inference that it is a Perl file, ...without the extension that is. Non-essential in this example, but would be nice...

  8. Log in to comment