--- a/src/pyams_utils/pygments.py Wed Nov 20 19:26:23 2019 +0100
+++ b/src/pyams_utils/pygments.py Fri Nov 22 18:51:37 2019 +0100
@@ -10,7 +10,11 @@
# FOR A PARTICULAR PURPOSE.
#
-__docformat__ = 'restructuredtext'
+"""PyAMS_utils.pygments module
+
+This module is used to provide an URL which allows you to load Pygments CSS files.
+It also provides two vocabularies of available lexers and styles.
+"""
from fanstatic import get_library_registry
from persistent import Persistent
@@ -21,16 +25,19 @@
from pyramid.response import Response
from pyramid.view import view_config
from zope.container.contained import Contained
-from zope.interface import Interface, implementer
-from zope.schema import Bool, Choice
from zope.schema.fieldproperty import FieldProperty
from zope.schema.vocabulary import SimpleTerm, SimpleVocabulary
from pyams_utils.factory import factory_config
from pyams_utils.fanstatic import ExternalResource
+from pyams_utils.interfaces.pygments import IPygmentsCodeConfiguration, \
+ PYGMENTS_LEXERS_VOCABULARY, PYGMENTS_STYLES_VOCABULARY
from pyams_utils.list import unique_iter
from pyams_utils.vocabulary import vocabulary_config
+
+__docformat__ = 'restructuredtext'
+
from pyams_utils import _
@@ -47,11 +54,13 @@
from pyams_default_theme import library
+# pylint: disable=invalid-name
pygments_css = ExternalResource(library, 'get-pygments-style.css', resource_type='css')
@view_config(name='get-pygments-style.css')
def get_pygments_style_view(request):
+ """View used to download Pygments style"""
style = request.params.get('style', 'default')
styles = HtmlFormatter(linenos='inline',
nowrap=False,
@@ -64,32 +73,28 @@
# Pygments lexers
#
-PYGMENTS_LEXERS_VOCABULARY = 'Pygments lexers vocabulary'
-
-
@vocabulary_config(name=PYGMENTS_LEXERS_VOCABULARY)
class PygmentsLexersVocabulary(SimpleVocabulary):
"""Pygments lexers vocabulary"""
- def __init__(self, context):
+ def __init__(self, context): # pylint: disable=unused-argument
terms = [SimpleTerm('auto', title=_("Automatic detection"))]
+ # pylint: disable=unused-variable
for name, aliases, filetypes, mimetypes in sorted(unique_iter(get_all_lexers(),
key=lambda x: x[0].lower()),
key=lambda x: x[0].lower()):
terms.append(SimpleTerm(aliases[0] if len(aliases) > 0 else name,
title='{0}{1}'.format(name,
- ' ({})'.format(', '.join(filetypes)) if filetypes else '')))
+ ' ({})'.format(', '.join(filetypes))
+ if filetypes else '')))
super(PygmentsLexersVocabulary, self).__init__(terms)
-PYGMENTS_STYLES_VOCABULARY = 'Pygments styles vocabulary'
-
-
@vocabulary_config(name=PYGMENTS_STYLES_VOCABULARY)
class PygmentsStylesVocabulary(SimpleVocabulary):
"""Pygments styles vocabulary"""
- def __init__(self, context):
+ def __init__(self, context): # pylint: disable=unused-argument
terms = []
for name in sorted(get_all_styles()):
terms.append(SimpleTerm(name))
@@ -100,33 +105,6 @@
# Pygments configuration
#
-class IPygmentsCodeConfiguration(Interface):
- """Pygments html formatter options"""
-
- lexer = Choice(title=_("Selected lexer"),
- description=_("Lexer used to format source code"),
- required=True,
- vocabulary=PYGMENTS_LEXERS_VOCABULARY,
- default='auto')
-
- display_linenos = Bool(title=_("Display line numbers?"),
- description=_("If 'no', line numbers will be hidden"),
- required=True,
- default=True)
-
- disable_wrap = Bool(title=_("Lines wrap?"),
- description=_("If 'yes', lines wraps will be enabled; line numbers will not be "
- "displayed if lines wrap is enabled..."),
- required=True,
- default=False)
-
- style = Choice(title=_("Color style"),
- description=_("Selected color style"),
- required=True,
- vocabulary=PYGMENTS_STYLES_VOCABULARY,
- default='default')
-
-
@factory_config(IPygmentsCodeConfiguration)
class PygmentsCodeRendererSettings(Persistent, Contained):
"""Pygments code renderer settings"""
@@ -149,3 +127,4 @@
cssclass='source',
style=settings.style)
return highlight(code, lexer, formatter)
+ return None