Skip to content

Commit

Permalink
sphinxext: style fixups
Browse files Browse the repository at this point in the history
  • Loading branch information
birkenfeld committed Oct 26, 2022
1 parent 8cb16e2 commit 2b45339
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions pygments/sphinxext.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,14 +87,15 @@ def run(self):

def document_lexers_overview(self):
"""Generate a tabular overview of all lexers.
The columns are the lexer name, the extensions handled by this lexer
(or "None"), the aliases and a link to the lexer class."""
from pygments.lexers._mapping import LEXERS
import pygments.lexers
out = []

table = []

def format_link(name, url):
if url:
return f'`{name} <{url}>`_'
Expand All @@ -105,14 +106,15 @@ def format_link(name, url):
extensions = lexer_cls.filenames + lexer_cls.alias_filenames

table.append({
'name' : format_link(data[1], lexer_cls.url),
'name': format_link(data[1], lexer_cls.url),
'extensions': ', '.join(extensions).replace('*', '\\*').replace('_', '\\') or 'None',
'aliases': ', '.join(data[2]),
'class': f'{data[0]}.{classname}'
})

column_names = ['name', 'extensions', 'aliases', 'class']
column_lengths = [max([len(row[column]) for row in table if row[column]]) for column in column_names]
column_lengths = [max([len(row[column]) for row in table if row[column]])
for column in column_names]

def write_row(*columns):
"""Format a table row"""
Expand All @@ -129,7 +131,7 @@ def write_seperator():
"""Write a table separator row"""
sep = ['='*c for c in column_lengths]
return write_row(*sep)

out.append(write_seperator())
out.append(write_row('Name', 'Extension(s)', 'Short name(s)', 'Lexer class'))
out.append(write_seperator())
Expand All @@ -143,7 +145,6 @@ def write_seperator():

return '\n'.join(out)


def document_lexers(self):
from pygments.lexers._mapping import LEXERS
out = []
Expand Down

0 comments on commit 2b45339

Please sign in to comment.