summaryrefslogtreecommitdiffstats
path: root/doc/docs/styledevelopment.rst
blob: 8c4ec2de2d79ec0b7f84cd1fded2c6af0f4ff1e6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
.. -*- mode: rst -*-

.. _creating-own-styles:

Creating Own Styles
===================

So, how to create a style? All you have to do is to subclass `Style` and
define some styles:

.. sourcecode:: python

    from pygments.style import Style
    from pygments.token import Token, Comment, Keyword, Name, String, \
         Error, Generic, Number, Operator


    class YourStyle(Style):

        styles = {
            Token:                  '',
            Comment:                'italic #888',
            Keyword:                'bold #005',
            Name:                   '#f00',
            Name.Class:             'bold #0f0',
            Name.Function:          '#0f0',
            String:                 'bg:#eee #111'
        }

That's it, save it as ``your.py``. There are just a few rules. When you define a style for `Name`
the style automatically also affects `Name.Function` and so on. If you
defined ``'bold'`` and you don't want boldface for a subtoken use ``'nobold'``.

(Philosophy: the styles aren't written in CSS syntax since this way
they can be used for a variety of formatters.)

``Token`` is the default style inherited by all token types.

To make the style usable for Pygments, you must

* either register it as a plugin (see :doc:`the plugin docs <plugins>`)
* or update the ``pygments.styles`` subpackage directory. For example:

  * add ``your.py`` file
  * register the new style by adding a line to the ``__init__.py`` file:
  
  .. sourcecode:: python
  
      STYLE_MAP = {
          ...
          'your':  'your::YourStyle',

.. note::

    You should *only* add it to the ``pygments.styles`` subdirectory if you are
    working on a contribution to Pygments. You should not use that
    method to extend an already existing copy of Pygments, use the plugins
    mechanism for that.


Style Rules
===========

Here a small overview of all allowed styles:

``bold``
    render text as bold
``nobold``
    don't render text as bold (to prevent subtokens being highlighted bold)
``italic``
    render text italic
``noitalic``
    don't render text as italic
``underline``
    render text underlined
``nounderline``
    don't render text underlined
``bg:``
    transparent background
``bg:#000000``
    background color (black)
``border:``
    no border
``border:#ffffff``
    border color (white)
``#ff0000``
    text color (red)
``noinherit``
    don't inherit styles from supertoken

Note that there may not be a space between ``bg:`` and the color value
since the style definition string is split at whitespace.
Also, using named colors is not allowed since the supported color names
vary for different formatters.

Furthermore, not all lexers might support every style.