Issue #181 resolved
Former user created an issue

Here a lexer for pygments that highlights debian sources.list files: {{{

!patch

Index: pygments/lexers/_mapping.py

--- pygments/lexers/_mapping.py (revision 2589) +++ pygments/lexers/_mapping.py (working copy) @@ -66,6 +66,7 @@ 'RubyLexer': ('pygments.lexers.agile', 'Ruby', ('rb', 'ruby'), ('.rb', '.rbw', 'Rakefile', '.rake', '.gemspec', '.rbx'), ('text/x-ruby', 'application/x-ruby')), 'SchemeLexer': ('pygments.lexers.agile', 'Scheme', ('scheme',), ('.scm',), ('text/x-scheme', 'application/x-scheme')), 'SmartyLexer': ('pygments.lexers.templates', 'Smarty', ('smarty',), ('.tpl',), ()), + 'SourcesListLexer': ('pygments.lexers.text', 'SourcesList', ('sourceslist', 'sources.list'), ('sources.list',), ()), 'SqlLexer': ('pygments.lexers.other', 'SQL', ('sql',), ('.sql',), ('text/x-sql',)), 'TexLexer': ('pygments.lexers.text', 'TeX', ('tex', 'latex'), ('.tex', '.aux', '.toc'), ('text/x-tex', 'text/x-latex')), 'TextLexer': ('pygments.lexers.special', 'Text only', ('text',), ('.txt',), ('text/plain',)), Index: pygments/lexers/text.py =================================================================== --- pygments/lexers/text.py (revision 2589) +++ pygments/lexers/text.py (working copy) @@ -19,7 +19,8 @@

all = ['IniLexer', 'MakefileLexer', 'DiffLexer', 'IrcLogsLexer', - 'TexLexer', 'GroffLexer', 'ApacheConfLexer', 'BBCodeLexer'] + 'TexLexer', 'GroffLexer', 'ApacheConfLexer', 'BBCodeLexer', + 'SourcesListLexer']

class IniLexer(RegexLexer): @@ -306,3 +307,28 @@ (r'[^\s"]+', Text) ] } + +class SourcesListLexer(RegexLexer): + """ + Lex debian sources.list files + """ + name= 'SourcesList' + aliases = ('sourceslist','sources.list') + filenames = ('sources.list',) + + tokens = { + 'root': [ + (r'#.?$', Comment), + (r'(deb(?:-src)?)(\s+)(\S+)(\s+)(\S+)([^#\n])', + bygroups(Name.Builtin, Text, Name.Class, Text, String, Text)) + ] + } + + def analyse_text(text): + for l in text.split('\n'): + l = l.strip() + if not (l.startswith('#') or l.startswith('deb ') or + l.startswith('deb-src ') or len(l) == 0): + return False + else: + return True }}}

Reported by Seveas

Comments (4)

  1. Anonymous

    that patch was contributed by Seveas. The trac just ate the reporter field, patched it so that guests can now choose a name :D

  2. Log in to comment