summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--CHANGES3
-rw-r--r--docs/src/styles.txt12
-rw-r--r--pygments/styles/__init__.py28
-rw-r--r--tests/test_basic_api.py4
4 files changed, 38 insertions, 9 deletions
diff --git a/CHANGES b/CHANGES
index 242e78ba..abe1f6c7 100644
--- a/CHANGES
+++ b/CHANGES
@@ -5,6 +5,9 @@ Version 0.7
-----------
(codename to be selected, released Feb XX, 2007)
+- Made it possible to just drop style modules into the `styles` subpackage
+ of the Pygments installation.
+
- Added a "state" keyword argument to the `using` helper.
- Added a `commandprefix` option to the `LatexFormatter` which allows to
diff --git a/docs/src/styles.txt b/docs/src/styles.txt
index f37b0b7c..d6ba8bd0 100644
--- a/docs/src/styles.txt
+++ b/docs/src/styles.txt
@@ -66,11 +66,21 @@ they can be used for a variety of formatters.)
`default_style` is the style inherited by all token types.
+To make the style usable for Pygments, you must
+
+* either register it as a plugin (see `the plugin docs <plugins.txt>`)
+* or drop it into the `styles` subpackage of your Pygments distribution one style
+ class per style, where the file name is the style name and the class name is
+ `StylenameClass`. For example, if your style should be called
+ ``"mondrian"``, name the class `MondrianStyle`, put it into the file
+ ``mondrian.py`` and this file into the ``pygments.styles`` subpackage
+ directory.
+
Style Rules
===========
-Here a small overview over all allowed styles:
+Here a small overview of all allowed styles:
``bold``
render text as bold
diff --git a/pygments/styles/__init__.py b/pygments/styles/__init__.py
index c75493b4..0e1819e9 100644
--- a/pygments/styles/__init__.py
+++ b/pygments/styles/__init__.py
@@ -30,20 +30,32 @@ STYLE_MAP = {
def get_style_by_name(name):
- if name not in STYLE_MAP:
+ if name in STYLE_MAP:
+ mod, cls = STYLE_MAP[name].split('::')
+ builtin = "yes"
+ else:
for found_name, style in find_plugin_styles():
if name == found_name:
return style
- raise ValueError("Style %r not found" % name)
-
- mod, cls = STYLE_MAP[name].split('::')
- mod = __import__('pygments.styles.' + mod, None, None, [cls])
- return getattr(mod, cls)
+ # perhaps it got dropped into our styles package
+ builtin = ""
+ mod = name
+ cls = name.title() + "Style"
+
+ try:
+ mod = __import__('pygments.styles.' + mod, None, None, [cls])
+ except ImportError:
+ raise ValueError("Style module %r not found" % mod +
+ (builtin and ", though it should be builtin") + ".")
+ try:
+ return getattr(mod, cls)
+ except AttributeError:
+ raise ValueError("Style class %r not found in style module." % cls)
def get_all_styles():
- """Return an generator for all styles by name.
- Both builtin and plugin."""
+ """Return an generator for all styles by name,
+ both builtin and plugin."""
for name in STYLE_MAP:
yield name
for name, _ in find_plugin_styles():
diff --git a/tests/test_basic_api.py b/tests/test_basic_api.py
index 2a967317..a8b4ea96 100644
--- a/tests/test_basic_api.py
+++ b/tests/test_basic_api.py
@@ -89,6 +89,10 @@ class FormattersTest(unittest.TestCase):
inst.get_style_defs()
inst.format(ts, out)
+ def test_styles(self):
+ from pygments.formatters import HtmlFormatter
+ fmt = HtmlFormatter(style="pastie")
+
def test_unicode_handling(self):
# test that the formatter supports encoding and Unicode
tokens = list(lexers.PythonLexer(encoding='utf-8').get_tokens("def f(): 'รค'"))