| 1 |
.. -*- mode: rst -*- |
| 2 |
|
| 3 |
==================== |
| 4 |
Write your own style |
| 5 |
==================== |
| 6 |
|
| 7 |
So, how to create a style? All you have to do is to subclass `Style` and |
| 8 |
define some styles: |
| 9 |
|
| 10 |
.. sourcecode:: python |
| 11 |
|
| 12 |
from pygments.style import Style |
| 13 |
from pygments.token import Token, Comment, Keyword, Name, String, \ |
| 14 |
Error, Generic, Number, Operator |
| 15 |
|
| 16 |
|
| 17 |
class YourStyle(Style): |
| 18 |
|
| 19 |
styles = { |
| 20 |
Token: '', |
| 21 |
Comment: 'italic #888', |
| 22 |
Keyword: 'bold #005', |
| 23 |
Name: '#f00', |
| 24 |
Name.Class: 'bold #0f0', |
| 25 |
Name.Function: '#0f0', |
| 26 |
String: 'bg:#eee #111' |
| 27 |
} |
| 28 |
|
| 29 |
That's it, save it as ``your.py``. There are just a few rules. When you define a style for `Name` |
| 30 |
the style automatically also affects `Name.Function` and so on. If you |
| 31 |
defined ``'bold'`` and you don't want boldface for a subtoken use ``'nobold'``. |
| 32 |
|
| 33 |
(Philosophy: the styles aren't written in CSS syntax since this way |
| 34 |
they can be used for a variety of formatters.) |
| 35 |
|
| 36 |
``Token`` is the default style inherited by all token types. |
| 37 |
|
| 38 |
To make the style usable for Pygments, you must |
| 39 |
|
| 40 |
* either register it as a plugin (see :doc:`the plugin docs <plugins>`) |
| 41 |
* or update the ``pygments.styles`` subpackage directory. For example: |
| 42 |
|
| 43 |
* add ``your.py`` file |
| 44 |
* regenerate the mappings file using ``tox -e mapfiles`` |
| 45 |
|
| 46 |
.. note:: |
| 47 |
|
| 48 |
You should *only* add it to the ``pygments.styles`` subdirectory if you are |
| 49 |
working on a contribution to Pygments. You should not use that |
| 50 |
method to extend an already existing copy of Pygments, use the plugins |
| 51 |
mechanism for that. |
| 52 |
|
| 53 |
|
| 54 |
Style Rules |
| 55 |
=========== |
| 56 |
|
| 57 |
Here a small overview of all allowed styles: |
| 58 |
|
| 59 |
``bold`` |
| 60 |
render text as bold |
| 61 |
``nobold`` |
| 62 |
don't render text as bold (to prevent subtokens being highlighted bold) |
| 63 |
``italic`` |
| 64 |
render text italic |
| 65 |
``noitalic`` |
| 66 |
don't render text as italic |
| 67 |
``underline`` |
| 68 |
render text underlined |
| 69 |
``nounderline`` |
| 70 |
don't render text underlined |
| 71 |
``bg:`` |
| 72 |
transparent background |
| 73 |
``bg:#000000`` |
| 74 |
background color (black) |
| 75 |
``border:`` |
| 76 |
no border |
| 77 |
``border:#ffffff`` |
| 78 |
border color (white) |
| 79 |
``#ff0000`` |
| 80 |
text color (red) |
| 81 |
``noinherit`` |
| 82 |
don't inherit styles from supertoken |
| 83 |
|
| 84 |
Note that there may not be a space between ``bg:`` and the color value |
| 85 |
since the style definition string is split at whitespace. |
| 86 |
Also, using named colors is not allowed since the supported color names |
| 87 |
vary for different formatters. |
| 88 |
|
| 89 |
Furthermore, not all lexers might support every style. |