1. Georg Brandl
  2. pygments-main
  3. Issues
Issue #892 closed

SourcesListLexer selected for any text starting with '#'

created an issue

The analyse_text method for SourcesListLexer is way too wide:

def analyse_text(text):
        for line in text.split('\n'):
            line = line.strip()
            if not (line.startswith('#') or line.startswith('deb ') or
                    line.startswith('deb-src ') or not line):
                return False
        return True

Any line starting with '#' or even an empty line is selected.

>>> from pygments.lexers import guess_lexer
>>> line="#!/usr/bin/perl"
>>> print(guess_lexer(line))

For me the result is that this lexer is chosen for perl files.

Maybe change it to:

if not (line.startswith('deb ') or line.startswith('deb-src '))

I notice that it correctly detects python files despite also having a shebang, so maybe this is also related to the order in which the lexers are checked. But I don't know enough about pygments to suggest how that could be changed!

Comments (2)

  1. Log in to comment