diff options
author | Georg Brandl <georg@python.org> | 2021-04-16 20:21:33 +0200 |
---|---|---|
committer | Georg Brandl <georg@python.org> | 2021-04-16 20:21:33 +0200 |
commit | 7fd3ff9b1a1a54d2d3ed2e4a4c43af25a03065a3 (patch) | |
tree | 00f3c7a30ee78da3abcc1c96355063da9b5aa0fe /doc/docs | |
parent | 027bbfd3e94f60f7bcfe024951d71ae19736916f (diff) | |
download | pygments-git-7fd3ff9b1a1a54d2d3ed2e4a4c43af25a03065a3.tar.gz |
docs: move style development section to its own doc.
Reference: #1571
Diffstat (limited to 'doc/docs')
-rw-r--r-- | doc/docs/index.rst | 1 | ||||
-rw-r--r-- | doc/docs/styledevelopment.rst | 83 | ||||
-rw-r--r-- | doc/docs/styles.rst | 77 |
3 files changed, 85 insertions, 76 deletions
diff --git a/doc/docs/index.rst b/doc/docs/index.rst index 1c96e62d..c3baa472 100644 --- a/doc/docs/index.rst +++ b/doc/docs/index.rst @@ -37,6 +37,7 @@ Pygments documentation lexerdevelopment formatterdevelopment filterdevelopment + styledevelopment plugins **Hints and tricks** diff --git a/doc/docs/styledevelopment.rst b/doc/docs/styledevelopment.rst new file mode 100644 index 00000000..01838699 --- /dev/null +++ b/doc/docs/styledevelopment.rst @@ -0,0 +1,83 @@ +.. -*- 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 Keyword, Name, Comment, String, Error, \ + Number, Operator, Generic + + class YourStyle(Style): + default_style = "" + styles = { + Comment: 'italic #888', + Keyword: 'bold #005', + Name: '#f00', + Name.Function: '#0f0', + Name.Class: 'bold #0f0', + String: 'bg:#eee #111' + } + +That's it. 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.) + +`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 :doc:`the plugin docs <plugins>`) +* 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 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. diff --git a/doc/docs/styles.rst b/doc/docs/styles.rst index 570293a5..b58d896a 100644 --- a/doc/docs/styles.rst +++ b/doc/docs/styles.rst @@ -39,82 +39,7 @@ Or you can also import your own style (which must be a subclass of 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 Keyword, Name, Comment, String, Error, \ - Number, Operator, Generic - - class YourStyle(Style): - default_style = "" - styles = { - Comment: 'italic #888', - Keyword: 'bold #005', - Name: '#f00', - Name.Function: '#0f0', - Name.Class: 'bold #0f0', - String: 'bg:#eee #111' - } - -That's it. 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.) - -`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 :doc:`the plugin docs <plugins>`) -* 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 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. +See :ref:`creating-own-styles`. Builtin Styles |