Python pygments.lexers.get_all_lexers() Examples

The following are 3 code examples of pygments.lexers.get_all_lexers(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module pygments.lexers , or try the search function .
Example #1
Source File: detect_missing_analyse_text.py    From pygments with BSD 2-Clause "Simplified" License 6 votes vote down vote up
def main():
    uses = {}

    for name, aliases, filenames, mimetypes in get_all_lexers():
        cls = find_lexer_class(name)
        if not cls.aliases:
            print(cls, "has no aliases")
        for f in filenames:
            if f not in uses:
                uses[f] = []
            uses[f].append(cls)

    ret = 0
    for k, v in uses.items():
        if len(v) > 1:
            #print "Multiple for", k, v
            for i in v:
                if i.analyse_text is None:
                    print(i, "has a None analyse_text")
                    ret |= 1
                elif Lexer.analyse_text.__doc__ == i.analyse_text.__doc__:
                    print(i, "needs analyse_text, multiple lexers for", k)
                    ret |= 2
    return ret 
Example #2
Source File: utility.py    From pinnwand with MIT License 5 votes vote down vote up
def list_languages() -> Dict[str, str]:
    # Start with converting the pygments lexers index into a dict.
    lexers = {lexer[1][0]: lexer[0] for lexer in get_all_lexers()}

    # Add autodetection option
    lexers["autodetect"] = "Autodetect"

    # Since dicts are sorted since Python 3.7 (and 3.6 per implementation
    # detail) and the Pygments ordering is a bit inane we sort and turn back
    # into a dict here.
    return dict(sorted(lexers.items(), key=lambda x: x[1])) 
Example #3
Source File: index.py    From bepasty-server with BSD 2-Clause "Simplified" License 5 votes vote down vote up
def index():
    contenttypes = [
        'text/x-bepasty-redirect',  # redirect / link shortener service
    ]
    for lexer_info in get_all_lexers():
        contenttypes.extend(lexer_info[3])
    return render_template('index.html', contenttypes=contenttypes)