diff options
author | gbrandl <devnull@localhost> | 2007-01-12 22:53:02 +0100 |
---|---|---|
committer | gbrandl <devnull@localhost> | 2007-01-12 22:53:02 +0100 |
commit | 75dee451b1902e95b91c97f998af4c38e4ce670a (patch) | |
tree | eb7a1df61a6a1d8b0d75ae1dd957005a1b680005 | |
parent | efaccf6fd1322930aca142dd1a96d06d1bae84a3 (diff) | |
download | pygments-75dee451b1902e95b91c97f998af4c38e4ce670a.tar.gz |
[svn] Generate lexer, formatter and filter docs from docstrings.
There is the problem of ordering, though.
-rw-r--r-- | Makefile | 2 | ||||
-rw-r--r-- | docs/generate.py | 128 | ||||
-rw-r--r-- | docs/src/filters.txt | 20 | ||||
-rw-r--r-- | docs/src/formatters.txt | 258 | ||||
-rw-r--r-- | docs/src/lexers.txt | 815 | ||||
-rw-r--r-- | pygments/filters/__init__.py | 12 | ||||
-rw-r--r-- | pygments/formatters/__init__.py | 8 | ||||
-rw-r--r-- | pygments/formatters/bbcode.py | 19 | ||||
-rw-r--r-- | pygments/formatters/html.py | 131 | ||||
-rw-r--r-- | pygments/formatters/latex.py | 62 | ||||
-rw-r--r-- | pygments/formatters/other.py | 16 | ||||
-rw-r--r-- | pygments/formatters/rtf.py | 14 | ||||
-rw-r--r-- | pygments/formatters/terminal.py | 30 | ||||
-rw-r--r-- | pygments/lexers/agile.py | 62 | ||||
-rw-r--r-- | pygments/lexers/compiled.py | 29 | ||||
-rw-r--r-- | pygments/lexers/dotnet.py | 17 | ||||
-rw-r--r-- | pygments/lexers/other.py | 17 | ||||
-rw-r--r-- | pygments/lexers/special.py | 11 | ||||
-rw-r--r-- | pygments/lexers/templates.py | 234 | ||||
-rw-r--r-- | pygments/lexers/text.py | 52 | ||||
-rw-r--r-- | pygments/lexers/web.py | 50 |
21 files changed, 744 insertions, 1243 deletions
@@ -10,7 +10,7 @@ PYTHON ?= python -export PYTHONPATH = $(shell python -c 'print ":".join(line.strip() for line in file("PYTHONPATH"))' 2>/dev/null) +export PYTHONPATH ?= $(shell python -c 'print ":".join(line.strip() for line in file("PYTHONPATH"))' 2>/dev/null) .PHONY: apidocs check clean clean-pyc codetags docs epydoc lexermap \ pylint reindent test diff --git a/docs/generate.py b/docs/generate.py index 91a280e3..abc4565a 100644 --- a/docs/generate.py +++ b/docs/generate.py @@ -2,7 +2,7 @@ # -*- coding: utf-8 -*- """ Generate Pygments Documentation - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Generates a bunch of html files containing the documentation. @@ -27,6 +27,77 @@ from pygments.lexers import get_lexer_by_name from pygments.formatters import HtmlFormatter +LEXERDOC = ''' +`%s` +%s + :Aliases: %s + :Filename patterns: %s + :Mimetypes: %s + +''' + +def generate_lexer_docs(): + from pygments.lexers import LEXERS + + out = [] + + modules = {} + moduledocstrings = {} + for classname, data in sorted(LEXERS.iteritems(), key=lambda x: x[0]): + module = data[0] + mod = __import__(module, fromlist=[classname]) + cls = getattr(mod, classname) + if not cls.__doc__: + print "Warning: %s does not have a docstring." % classname + modules.setdefault(module, []).append(( + classname, + cls.__doc__, + ', '.join(data[2]) or 'None', + ', '.join(data[3]).replace('*', '\\*') or 'None', + ', '.join(data[4]) or 'None')) + if module not in moduledocstrings: + moduledocstrings[module] = mod.__doc__ + + for module, lexers in sorted(modules.iteritems(), key=lambda x: x[0]): + heading = moduledocstrings[module].splitlines()[4].strip().rstrip('.') + out.append('\n' + heading + '\n' + '-'*len(heading) + '\n') + for data in lexers: + out.append(LEXERDOC % data) + return ''.join(out) + +def generate_formatter_docs(): + from pygments.formatters import FORMATTERS + + out = [] + for cls, data in FORMATTERS.iteritems(): + heading = cls.__name__ + out.append('`' + heading + '`\n' + '-'*(2+len(heading)) + '\n') + out.append(cls.__doc__) + out.append(''' + :Aliases: %s + :Filename patterns: %s + + +''' % (', '.join(data[1]) or 'None', ', '.join(data[2]).replace('*', '\\*') or 'None')) + return ''.join(out) + +def generate_filter_docs(): + from pygments.filters import FILTERS + + out = [] + for name, cls in FILTERS.iteritems(): + out.append(''' +`%s` +%s + :Name: %s +''' % (cls.__name__, cls.__doc__, name)) + return ''.join(out) + +LEXERDOCS = generate_lexer_docs() +FORMATTERDOCS = generate_formatter_docs() +FILTERDOCS = generate_filter_docs() + + PYGMENTS_FORMATTER = HtmlFormatter(style='pastie', cssclass='syntax') USAGE = '''\ @@ -207,24 +278,7 @@ div.toc { div.toc h2 { font-size: 20px; } -''' - - -def generate_documentation(data, link_style): - writer = DocumentationWriter(link_style) - parts = publish_parts( - data, - writer=writer, - settings_overrides={ - 'initial_header_level': 3, - 'field_name_limit': 50, - } - ) - return { - 'title': parts['title'].encode('utf-8'), - 'body': parts['body'].encode('utf-8'), - 'toc': parts['toc'] - } +''' #' def pygments_directive(name, arguments, options, content, lineno, @@ -241,6 +295,16 @@ pygments_directive.content = 1 directives.register_directive('sourcecode', pygments_directive) +def create_translator(link_style): + class Translator(html4css1.HTMLTranslator): + def visit_reference(self, node): + refuri = node.get('refuri') + if refuri is not None and '/' not in refuri and refuri.endswith('.txt'): + node['refuri'] = link_style(refuri[:-4]) + html4css1.HTMLTranslator.visit_reference(self, node) + return Translator + + class DocumentationWriter(html4css1.Writer): def __init__(self, link_style): @@ -279,14 +343,24 @@ class DocumentationWriter(html4css1.Writer): return [] -def create_translator(link_style): - class Translator(html4css1.HTMLTranslator): - def visit_reference(self, node): - refuri = node.get('refuri') - if refuri is not None and '/' not in refuri and refuri.endswith('.txt'): - node['refuri'] = link_style(refuri[:-4]) - html4css1.HTMLTranslator.visit_reference(self, node) - return Translator +def generate_documentation(data, link_style): + writer = DocumentationWriter(link_style) + data = data.replace('[builtin_lexer_docs]', LEXERDOCS).\ + replace('[builtin_formatter_docs]', FORMATTERDOCS).\ + replace('[builtin_filter_docs]', FILTERDOCS) + parts = publish_parts( + data, + writer=writer, + settings_overrides={ + 'initial_header_level': 3, + 'field_name_limit': 50, + } + ) + return { + 'title': parts['title'].encode('utf-8'), + 'body': parts['body'].encode('utf-8'), + 'toc': parts['toc'] + } def handle_python(filename, fp, dst): diff --git a/docs/src/filters.txt b/docs/src/filters.txt index 570be584..ecda206d 100644 --- a/docs/src/filters.txt +++ b/docs/src/filters.txt @@ -39,22 +39,4 @@ If you want to write your own filter, have a look at `Write your own filter`_. Builtin Filters =============== -`CodeTagFilter` - - Highlights special code tags in comments and docstrings. Per default, the - list of highlighted tags is ``XXX``, ``TODO``, ``BUG`` and ``NOTE``. You can - override this list by specifying a `codetags` parameter that takes a list of - words. - - :Name: ``codetagify`` - - -`KeywordCaseFilter` - - Converts keywords to ``lower``, ``upper`` or ``capitalize`` which means - first letter uppercase, rest lowercase. This can be useful e.g. if you - highlight Pascal code and want to adapt the code to your styleguide. The - default is ``lower``, override that by providing the `keywordcase` - parameter. - - :Name: ``keywordcase`` +[builtin_filter_docs] diff --git a/docs/src/formatters.txt b/docs/src/formatters.txt index 4eb64e7d..3832a3f1 100644 --- a/docs/src/formatters.txt +++ b/docs/src/formatters.txt @@ -59,260 +59,4 @@ Formatter classes All these classes are importable from `pygments.formatters`. - -`HtmlFormatter` ---------------- - - Formats tokens as HTML 4 ``<span>`` tags within a ``<pre>`` tag, wrapped - in a ``<div>`` tag. The ``<div>``'s CSS class can be set by the `cssclass` - option. - - If the `linenos` option is given and true, the ``<pre>`` is additionally - wrapped inside a ``<table>`` which has one row and two cells: one - containing the line numbers and one containing the code. Example: - - .. sourcecode:: html - - <div class="highlight" > - <table><tr> - <td class="linenos" title="click to toggle" - onclick="with (this.firstChild.style) - { display = (display == '') ? 'none' : '' }"> - <pre>1 - 2</pre> - </td> - <td class="code"> - <pre><span class="Ke">def </span><span class="NaFu">foo</span>(bar): - <span class="Ke">pass</span> - </pre> - </td> - </tr></table></div> - - (whitespace added to improve clarity). Wrapping can be disabled using the - `nowrap` option. - - With the `full` option, a complete HTML 4 document is output, including - the style definitions inside a ``<style>`` tag, or in a separate file if - the `cssfile` option is given. - - The `get_style_defs(arg='')` method of a `HtmlFormatter` returns a string - containing CSS rules for the CSS classes used by the formatter. The - argument `arg` can be used to specify additional CSS selectors that - are prepended to the classes. A call `fmter.get_style_defs('td .code')` - would result in the following CSS classes: - - .. sourcecode:: css - - td .code .kw { font-weight: bold; color: #00FF00 } - td .code .cm { color: #999999 } - ... - - If you have pygments 0.6 or higher you can also pass a list of tuple to the - `get_style_defs` method to request multiple prefixes for the tokens: - - .. sourcecode:: python - - formatter.get_style_defs(['div.syntax pre', 'pre.syntax']) - - The output would then look like this: - - .. sourcecode:: css - - div.syntax pre .kw, - pre.syntax .kw { font-weight: bold; color: #00FF00 } - div.syntax pre .cm, - pre.syntax .cm { color: #999999 } - ... - - Additional options accepted by the `HtmlFormatter`: - - `nowrap` - If set to ``True``, don't wrap the tokens at all, not even in a ``<pre>`` - tag. This disables all other options (default: ``False``). - - `noclasses` - If set to true, token ``<span>`` tags will not use CSS classes, but - inline styles. This is not recommended for larger pieces of code since - it increases output size by quite a bit (default: ``False``). - - `classprefix` - Since the token types use relatively short class names, they may clash - with some of your own class names. In this case you can use the - `classprefix` option to give a string to prepend to all Pygments-generated - CSS class names for token types. - Note that this option also affects the output of `get_style_defs()`. - - `cssclass` - CSS class for the wrapping ``<div>`` tag (default: ``'highlight'``). - - `cssstyles` - Inline CSS styles for the wrapping ``<div>`` tag (default: ``''``). - - `cssfile` - If the `full` option is true and this option is given, it must be the - name of an external file. The stylesheet is then written to this file - instead of the HTML file. *New in Pygments 0.6.* - - `linenospecial` - If set to a number n > 0, every nth line number is given the CSS - class ``"special"`` (default: ``0``). - - `nobackground` - If set to ``True``, the formatter won't output the background color - for the wrapping element (this automatically defaults to ``False`` - when there is no wrapping element [eg: no argument for the - `get_syntax_defs` method given]) (default: ``False``). *New in - Pygments 0.6.* - - :Aliases: ``html`` - :Filename patterns: ``*.html``, ``*.htm`` - - -`LatexFormatter` ----------------- - - Formats tokens as LaTeX code. This needs the `fancyvrb` and `color` - standard packages. - - Without the `full` option, code is formatted as one ``Verbatim`` - environment, like this: - - .. sourcecode:: latex - - \begin{Verbatim}[commandchars=@\[\]] - @Can[def ]@Cax[foo](bar): - @Can[pass] - \end{Verbatim} - - The command sequences used here (``@Can`` etc.) are generated from the given - `style` and can be retrieved using the `get_style_defs` method. - - With the `full` option, a complete LaTeX document is output, including - the command definitions in the preamble. - - The `get_style_defs(arg='')` method of a `LatexFormatter` returns a string - containing ``\newcommand`` commands defining the commands used inside the - ``Verbatim`` environments. If the argument `arg` is true, - ``\renewcommand`` is used instead. - - Additional options accepted by the `LatexFormatter`: - - `docclass` - If the `full` option is enabled, this is the document class to use - (default: ``'article'``). - - `preamble` - If the `full` option is enabled, this can be further preamble commands, - e.g. ``\usepackage`` (default: ``''``). - - `verboptions` - Additional options given to the Verbatim environment (see the *fancyvrb* - docs for possible values) (default: ``''``). - - :Aliases: ``latex``, ``tex`` - :Filename pattern: ``*.tex`` - - -`RtfFormatter` --------------- - - Formats tokens as RTF markup. This formatter automatically outputs full RTF - documents with color information and other useful stuff. Perfect for Copy and - Paste into Microsoft® Word® documents. - - *New in Pygments 0.6.* - - Additional options accepted by the `RtfFormatter`: - - `fontface` - The used font famliy, for example ``Bitstream Vera Sans``. Defaults to - some generic font which is supposed to have fixed width. - - :Aliases: ``rtf`` - :Filename pattern: ``*.rtf`` - - -`BBCodeFormatter` ------------------ - - Formats tokens with BBcodes. These formatting codes are used by many - bulletin boards, so you can highlight your sourcecode with pygments before - posting it there. - - This formatter has no support for background colors and borders, as there - are no common BBcode tags for that. - - Some board systems (e.g. phpBB) don't support colors in their [code] tag, - so you can't use the highlighting together with that tag. - Text in a [code] tag usually is shown with a monospace font (which this - formatter can do with the ``monofont`` option) and no spaces (which you - need for indentation) are removed. - - The `BBCodeFormatter` accepts two additional option: - - `codetag` - If set to true, put the output into ``[code]`` tags (default: - ``false``) - - `monofont` - If set to true, add a tag to show the code with a monospace font - (default: ``false``). - - :Aliases: ``bbcode``, ``bb`` - :Filename pattern: None - - -`TerminalFormatter` -------------------- - - Formats tokens with ANSI color sequences, for output in a text console. - Color sequences are terminated at newlines, so that paging the output - works correctly. - - The `get_style_defs()` method doesn't do anything special since there is - no support for common styles. - - The TerminalFormatter class supports only these options: - - `bg` - Set to ``"light"`` or ``"dark"`` depending on the terminal's background - (default: ``"light"``). - - `colorscheme` - A dictionary mapping token types to (lightbg, darkbg) color names or - ``None`` (default: ``None`` = use builtin colorscheme). - - `debug` - If this option is true, output the string "<<ERROR>>" after each error - token. This is meant as a help for debugging Pygments (default: ``False``). - - :Aliases: ``terminal``, ``console`` - :Filename pattern: None - - -`RawTokenFormatter` -------------------- - - Formats tokens as a raw representation for storing token streams. - - The format is ``tokentype<TAB>repr(tokenstring)\n``. The output can later - be converted to a token stream with the `RawTokenLexer`, described in the - `lexer list <lexers.txt>`_. - - One option is accepted: - - `compress` - If set to ``'gz'`` or ``'bz2'``, compress the output with the given - compression algorithm after encoding (default: ``''``). - - :Aliases: ``raw``, ``tokens`` - :Filename pattern: ``*.raw`` - - -`NullFormatter` ---------------- - - Just output all tokens, don't format in any way. - - :Aliases: ``text``, ``null`` - :Filename pattern: ``*.txt`` +[builtin_formatter_docs] diff --git a/docs/src/lexers.txt b/docs/src/lexers.txt index 262f92f2..2727f8ca 100644 --- a/docs/src/lexers.txt +++ b/docs/src/lexers.txt @@ -33,820 +33,7 @@ Currently, **all lexers** support these options: These lexers are builtin and can be imported from `pygments.lexers`: - -Special lexers -============== - -`TextLexer` - - "Null" lexer, doesn't highlight anything. - - :Aliases: ``text`` - :Filename patterns: ``*.txt`` - :Mimetypes: ``text/plain`` - - -`RawTokenLexer` - - Recreates a token stream formatted with the `RawTokenFormatter`. - - Additional option: - - `compress` - If set to ``'gz'`` or ``'bz2'``, decompress the token stream with - the given compression algorithm before lexing (default: ''). - - :Aliases: ``raw`` - :Filename patterns: ``*.raw`` - :Mimetypes: ``application/x-pygments/tokens`` - - -Agile languages -=============== - -`PythonLexer` - - For `Python <http://www.python.org>`_ source code. - - :Aliases: ``python``, ``py`` - :Filename patterns: ``*.py``, ``*.pyw`` - :Mimetypes: ``text/x-python``, ``application/x-python`` - - -`PythonConsoleLexer` - - For Python console output or doctests, such as: - - .. sourcecode:: pycon - - >>> a = 'foo' - >>> print a - foo - >>> 1 / 0 - Traceback (most recent call last): - File "<stdin>", line 1, in <module> - ZeroDivisionError: integer division or modulo by zero - - :Aliases: ``pycon`` - :Filename patterns: None - :Mimetypes: None - - -`PythonTracebackLexer` - - For Python tracebacks. - - *New in Pygments 0.7.* - - :Aliases: ``pytb`` - :Filename patterns: ``*.pytb`` - :Mimetypes: ``application/x-python-traceback`` - - -`RubyLexer` - - For `Ruby <http://www.ruby-lang.org>`_ source code. - - :Aliases: ``ruby``, ``rb`` - :Filename patterns: ``*.rb`` - :Mimetypes: ``text/x-ruby``, ``application/x-ruby`` - - -`RubyConsoleLexer` - - For Ruby interactive console (**irb**) output like: - - .. sourcecode:: rbcon - - irb(main):001:0> a = 1 - => 1 - irb(main):002:0> puts a - 1 - => nil - - :Aliases: ``rbcon``, ``irb`` - :Filename patterns: None - :Mimetypes: None - - -`PerlLexer` - - For `Perl <http://www.perl.org>`_ source code. - - :Aliases: ``perl``, ``pl`` - :Filename patterns: ``*.pl``, ``*.pm`` - :Mimetypes: ``text/x-perl``, ``application/x-perl`` - - -`LuaLexer` - - For `Lua <http://www.lua.org>`_ source code. - - Additional options: - - `func_name_highlighting` - If given and ``True``, highlight builtin function names - (default: ``True``). - `disabled_modules` - If given, must be a list of module names whose function names - should not be highlighted. By default all modules are highlighted. - - To get a list of allowed modules have a look into the - `_luabuiltins` module: - - .. sourcecode:: pycon - - >>> from pygments.lexers._luabuiltins import MODULES - >>> MODULES.keys() - ['string', 'coroutine', 'modules', 'io', 'basic', ...] - - :Aliases: ``lua`` - :Filename patterns: ``*.lua`` - :Mimetypes: ``text/x-lua``, ``application/x-lua`` - - -`SchemeLexer` - - For Scheme source code. It supports the whole R5RS specification. - - *New in Pygments 0.6.* - - :Aliases: ``scheme`` - :Filename patterns: ``*.scm`` - :Mimetypes: ``text/x-scheme``, ``application/x-scheme`` - - -Compiled languages -================== - -`CLexer` - - For C source code with preprocessor directives. - - :Aliases: ``c`` - :Filename patterns: ``*.c``, ``*.h`` - :Mimetypes: ``text/x-chdr``, ``text/x-csrc`` - - -`CppLexer` - - For C++ source code with preprocessor directives. - - :Aliases: ``cpp``, ``c++`` - :Filename patterns: ``*.cpp``, ``*.hpp``, ``*.c++``, ``*.h++`` - :Mimetypes: ``text/x-c++hdr``, ``text/x-c++src`` - - -`DelphiLexer` - - For `Delphi <http://www.borland.com/delphi/>`_ - (Borland Object Pascal) source code. - - :Aliases: ``delphi``, ``pas``, ``pascal``, ``objectpascal`` - :Filename patterns: ``*.pas`` - :Mimetypes: ``text/x-pascal`` - - -`JavaLexer` - - For `Java <http://www.sun.com/java/>`_ source code. - - :Aliases: ``java`` - :Filename patterns: ``*.java`` - :Mimetypes: ``text/x-java`` - - -.NET languages -============== - -`CSharpLexer` - - For `C# <http://msdn2.microsoft.com/en-us/vcsharp/default.aspx>`_ - source code. - - :Aliases: ``c#``, ``csharp`` - :Filename patterns: ``*.cs`` - :Mimetypes: ``text/x-csharp`` - - -`BooLexer` - - For `Boo <http://boo.codehaus.org/>`_ source code. - - :Aliases: ``boo`` - :Filename patterns: ``*.boo`` - :Mimetypes: ``text/x-boo`` - - -`VbNetLexer` - - For - `Visual Basic.NET <http://msdn2.microsoft.com/en-us/vbasic/default.aspx>`_ - source code. - - :Aliases: ``vbnet``, ``vb.net`` - :Filename patterns: ``*.vb``, ``*.bas`` - :Mimetypes: ``text/x-vbnet``, ``text/x-vba`` - - -Web-related languages -===================== - -`JavascriptLexer` - - For JavaScript source code. - - :Aliases: ``js``, ``javascript`` - :Filename patterns: ``*.js`` - :Mimetypes: ``text/x-javascript``, ``application/x-javascript``, ``text/javascript`` - - -`CssLexer` - - For CSS (Cascading Style Sheets). - - :Aliases: ``css`` - :Filename patterns: ``*.css`` - :Mimetypes: ``text/css`` - - -`HtmlLexer` - - For HTML 4 and XHTML 1 markup. Nested JavaScript and CSS is highlighted - by the appropriate lexer. - - :Aliases: ``html`` - :Filename patterns: ``*.html``, ``*.htm``, ``*.xhtml`` - :Mimetypes: ``text/html``, ``application/xhtml+xml`` - - -`PhpLexer` - - For `PHP <http://www.php.net/>`_ source code. - For PHP embedded in HTML, use the `HtmlPhpLexer`. - - Additional options: - - `startinline` - If given and ``True`` the lexer starts highlighting with - php code. (i.e.: no starting ``<?php`` required) - `funcnamehighlighting` - If given and ``True``, highlight builtin function names - (default: ``True``). - `disabledmodules` - If given, must be a list of module names whose function names - should not be highlighted. By default all modules are highlighted - except the special ``'unknown'`` module that includes functions - that are known to php but are undocumented. - - To get a list of allowed modules have a look into the - `_phpbuiltins` module: - - .. sourcecode:: pycon - - >>> from pygments.lexers._phpbuiltins import MODULES - >>> MODULES.keys() - ['PHP Options/Info', 'Zip', 'dba', ...] - - In fact the names of those modules match the module names from - the php documentation. - - :Aliases: ``php``, ``php3``, ``php4``, ``php5`` - :Filename patterns: ``*.php``, ``*.php[345]`` - :Mimetypes: None - - -`XmlLexer` - - Generic lexer for XML (extensible markup language). - - :Aliases: ``xml`` - :Filename patterns: ``*.xml`` - :Mimetypes: ``text/xml``, ``application/xml``, ``image/svg+xml``, - ``application/rss+xml``, ``application/atom+xml``, - ``application/xsl+xml``, ``application/xslt+xml`` - - -Template languages -================== - -`ErbLexer` - - Generic `ERB <http://ruby-doc.org/core/classes/ERB.html>`_ (Ruby Templating) - lexer. - - Just highlights ruby code between the preprocessor directives, other data - is left untouched by the lexer. - - All options are also forwarded to the `RubyLexer`. - - :Aliases: ``erb`` - :Filename patterns: None - :Mimetypes: None - - -`RhtmlLexer` - - Subclass of the ERB lexer that highlights the unlexed data with the - html lexer. - - Nested Javascript and CSS is highlighted too. - - :Aliases: ``rhtml``, ``html+erb``, ``html+ruby`` - :Filename patterns: ``*.rhtml`` - :Mimetypes: None - - -`XmlErbLexer` - - Subclass of `ErbLexer` which highlights data outside preprocessor - directives with the `XmlLexer`. - - :Aliases: ``xml+erb``, ``xml+ruby`` - :Filename patterns: None - :Mimetypes: None - - -`CssErbLexer` - - Subclass of `ErbLexer` which highlights unlexed data with the `CssLexer`. - - :Aliases: ``css+erb``, ``css+ruby`` - :Filename patterns: None - :Mimetypes: None - - -`JavascriptErbLexer` - - Subclass of `ErbLexer` which highlights unlexed data with the - `JavascriptLexer`. - - :Aliases: ``js+erb``, ``javascript+erb``, ``js+ruby``, ``javascript+ruby`` - :Filename patterns: None - :Mimetypes: None - - -`HtmlPhpLexer` - - Subclass of `PhpLexer` that highlights unhandled data with the `HtmlLexer`. - - Nested Javascript and CSS is highlighted too. - - :Aliases: ``html+php`` - :Filename patterns: ``*.phtml`` - :Mimetypes: ``text/x-php``, ``application/x-php``, - ``application/x-httpd-php``, ``application/x-httpd-php3``, - ``application/x-httpd-php4``, ``application/x-httpd-php5`` - - -`XmlPhpLexer` - - Subclass of `PhpLexer` that higlights unhandled data with the `XmlLexer`. - - :Aliases: ``xml+php`` - :Filename patterns: None - :Mimetypes: None - - -`CssPhpLexer` - - Subclass of `PhpLexer` which highlights unmatched data with the `CssLexer`. - - :Aliases: ``css+php`` - :Filename patterns: None - :Mimetypes: None - - -`JavascriptPhpLexer` - - Subclass of `PhpLexer` which highlights unmatched data with the - `JavascriptLexer`. - - :Aliases: ``js+php``, ``javascript+php`` - :Filename patterns: None - :Mimetypes: None - - -`DjangoLexer` - - Generic `django <http://www.djangoproject.com/documentation/templates/>`_ - and `jinja <http://wsgiarea.pocoo.org/jinja/>`_ template lexer. - - It just highlights django/jinja code between the preprocessor directives, - other data is left untouched by the lexer. - - :Aliases: ``django``, ``jinja`` - :Filename patterns: None - :Mimetypes: None - - -`HtmlDjangoLexer` - - Subclass of the `DjangoLexer` that highighlights unlexed data with the - `HtmlLexer`. - - Nested Javascript and CSS is highlighted too. - - :Aliases: ``html+django``, ``html+jinja`` - :Filename patterns: None - :Mimetypes: None - - -`XmlDjangoLexer` - - Subclass of the `DjangoLexer` that highlights unlexed data with the - `XmlLexer`. - - :Aliases: ``xml+django``, ``xml+jinja`` - :Filename patterns: None - :Mimetypes: None - - -`CssDjangoLexer` - - Subclass of the `DjangoLexer` that highlights unlexed data with the - `CssLexer`. - - :Aliases: ``css+django``, ``css+jinja`` - :Filename patterns: None - :Mimetypes: None - - -`JavascriptDjangoLexer` - - Subclass of the `DjangoLexer` that highlights unlexed data with the - `JavascriptLexer`. - - :Aliases: ``javascript+django``, ``js+django``, - ``javascript+jinja``, ``js+jinja`` - :Filename patterns: None - :Mimetypes: None - - -`SmartyLexer` - - Generic `Smarty <http://smarty.php.net/>`_ template lexer. - - Just highlights smarty code between the preprocessor directives, other - data is left untouched by the lexer. - - :Aliases: ``smarty`` - :Filename patterns: None - :Mimetypes: None - - -`HtmlSmartyLexer` - - Subclass of the `SmartyLexer` that highighlights unlexed data with the - `HtmlLexer`. - - Nested Javascript and CSS is highlighted too. - - :Aliases: ``html+smarty`` - :Filename patterns: None - :Mimetypes: None - - -`XmlSmartyLexer` - - Subclass of the `SmartyLexer` that highlights unlexed data with the - `XmlLexer`. - - :Aliases: ``xml+smarty`` - :Filename patterns: None - :Mimetypes: None - - -`CssSmartyLexer` - - Subclass of the `SmartyLexer` that highlights unlexed data with the - `CssLexer`. - - :Aliases: ``css+smarty`` - :Filename patterns: None - :Mimetypes: None - - -`JavascriptSmartyLexer` - - Subclass of the `SmartyLexer` that highlights unlexed data with the - `JavascriptLexer`. - - :Aliases: ``javascript+smarty`` - :Filename patterns: None - :Mimetypes: None - - -`GenshiTextLexer` - - A lexer that highlights `genshi <http://genshi.edgewall.org/>`_ text - templates. - - :Aliases: ``genshitext`` - :Filename patterns: None - :Mimetypes: None - - -`HtmlGenshiLexer` - - A lexer that highlights `genshi <http://genshi.edgewall.org/>`_ and - `kid <http://kid-templating.org/>`_ kid HTML templates. - - :Aliases: ``html+genshi``, ``html+kid`` - :Filename patterns: None - :Mimetypes: None - - -`GenshiLexer` - - A lexer that highlights `genshi <http://genshi.edgewall.org/>`_ and - `kid <http://kid-templating.org/>`_ kid XML templates. - - :Aliases: ``genshi``, ``kid``, ``xml+genshi``, ``xml.kid`` - :Filename patterns: ``*.kid`` - :Mimetypes: None - - -`JavascriptGenshiLexer` - - A lexer that highlights javascript code in genshi text templates. - - :Aliases: ``js+genshitext``, ``js+genshi``, ``javascript+genshitext``, - ``javascript+genshi`` - :Filename patterns: None - :Mimetypes: None - - -`CssGenshiLexer` - - A lexer that highlights CSS definitions in genshi text templates. - - :Aliases: ``css+genshitext``, ``css+genshi`` - :Filename patterns: None - :Mimetypes: None - - -`MyghtyLexer` - - Generic `myghty templates`_ lexer. Code that isn't Myghty - markup is yielded as `Token.Other`. - - *New in Pygments 0.6.* - - .. _myghty templates: http://www.myghty.org/ - - :Aliases: ``myghty`` - :Filename patterns: ``*.myt``, ``autodelegate`` - :Mimetypes: None - - -`MyghtyHtmlLexer` - - Subclass of the `MyghtyLexer` that highlights unlexer data - with the `HtmlLexer`. - - *New in Pygments 0.6.* - - :Aliases: ``html+myghty`` - :Filename patterns: None - :Mimetypes: None - - -`MyghtyXmlLexer` - - Subclass of the `MyghtyLexer` that highlights unlexer data - with the `XmlLexer`. - - *New in Pygments 0.6.* - - :Aliases: ``xml+myghty`` - :Filename patterns: None - :Mimetypes: None - - -`MyghtyJavascriptLexer` - - Subclass of the `MyghtyLexer` that highlights unlexer data - with the `JavascriptLexer`. - - *New in Pygments 0.6.* - - :Aliases: ``js+myghty``, ``javascript+myghty`` - :Filename patterns: None - :Mimetypes: None - - -`MyghtyCssLexer` - - Subclass of the `MyghtyLexer` that highlights unlexer data - with the `CssLexer`. - - *New in Pygments 0.6.* - - :Aliases: ``css+myghty`` - :Filename patterns: None - :Mimetypes: None - - -`MakoLexer` - - Generic `mako templates`_ lexer. Code that isn't Mako - markup is yielded as `Token.Other`. - - *New in Pygments 0.7.* - - .. _mako templates: http://www.makotemplates.org/ - - :Aliases: ``mako`` - :Filename patterns: ``*.mao`` - :Mimetypes: None - - -`MakoHtmlLexer` - - Subclass of the `MakoLexer` that highlights unlexer data - with the `HtmlLexer`. - - *New in Pygments 0.7.* - - :Aliases: ``html+mako`` - :Filename patterns: None - :Mimetypes: None - - -`MakoXmlLexer` - - Subclass of the `MakoLexer` that highlights unlexer data - with the `XmlLexer`. - - *New in Pygments 0.7.* - - :Aliases: ``xml+mako`` - :Filename patterns: None - :Mimetypes: None - - -`MakoJavascriptLexer` - - Subclass of the `MakoLexer` that highlights unlexer data - with the `JavascriptLexer`. - - *New in Pygments 0.7.* - - :Aliases: ``js+mako``, ``javascript+mako`` - :Filename patterns: None - :Mimetypes: None - - -`MakoCssLexer` - - Subclass of the `MakoLexer` that highlights unlexer data - with the `CssLexer`. - - *New in Pygments 0.7.* - - :Aliases: ``css+mako`` - :Filename patterns: None - :Mimetypes: None - - -Other languages -=============== - -`SqlLexer` - - Lexer for Structured Query Language. Currently, this lexer does - not recognize any special syntax except ANSI SQL. - - :Aliases: ``sql`` - :Filename patterns: ``*.sql`` - :Mimetypes: ``text/x-sql`` - - -`BrainfuckLexer` - - Lexer for the esoteric `BrainFuck <http://www.muppetlabs.com/~breadbox/bf/>`_ - language. - - :Aliases: ``brainfuck`` - :Filename patterns: ``*.bf``, ``*.b`` - :Mimetypes: None - - -`BashLexer` - - Lexer for (ba)sh shell scripts. - - *New in Pygments 0.6.* - - :Aliases: ``bash``, ``sh`` - :Filename patterns: ``*.sh`` - :Mimetypes: ``application/x-sh``, ``application/x-shellscript`` - - -Text lexers -=========== - -`IniLexer` - - Lexer for configuration files in INI style. - - :Aliases: ``ini``, ``cfg`` - :Filename patterns: ``*.ini``, ``*.cfg`` - :Mimetypes: None - - -`MakefileLexer` - - Lexer for Makefiles. - - :Aliases: ``make``, ``makefile``, ``mf`` - :Filename patterns: ``*.mak``, ``Makefile``, ``makefile`` - :Mimetypes: ``text/x-makefile`` - - -`DiffLexer` - - Lexer for unified or context-style diffs. - - :Aliases: ``diff`` - :Filename patterns: ``*.diff``, ``*.patch`` - :Mimetypes: ``text/x-diff``, ``text/x-patch`` - - -`IrcLogsLexer` - - Lexer for IRC logs in **irssi** or **xchat** style. - - :Aliases: ``irc`` - :Filename patterns: None - :Mimetypes: None - - -`TexLexer` - - Lexer for the TeX and LaTeX typesetting languages. - - :Aliases: ``tex``, ``latex`` - :Filename patterns: ``*.tex``, ``*.aux``, ``*.toc`` - :Mimetypes: ``text/x-tex``, ``text/x-latex`` - - -`GroffLexer` - - Lexer for the (g)roff typesetting language, supporting groff - extensions. Mainly useful for highlighting manpage sources. - - *New in Pygments 0.6.* - - :Aliases: ``groff``, ``nroff``, ``man`` - :Filename patterns: ``*.[1234567]``, ``*.man`` - :Mimetypes: ``text/troff``, ``application/x-troff`` - - -`ApacheConfLexer` - - Lexer for configuration files following the Apache config file - format. - - *New in Pygments 0.6.* - - :Aliases: ``apacheconf``, ``aconf``, ``apache`` - :Filename patterns: ``.htaccess``, ``apache.conf``, ``apache2.conf`` - :Mimetypes: None - - -`SourcesListLexer` - - Lexer that highlights debian sources.list files. - - *New in Pygments 0.7.* - - :Aliases: ``sources.list``, ``sourceslist`` - :Filename patterns: ``sources.list`` - :Mimetypes: None - - -`BBCodeLexer` - - A Lexer that highlights BBCode(-like) syntax. - - *New in Pygments 0.6.* - - :Aliases: ``bbcode`` - :Filename patterns: None - :Mimetypes: None - - -`MoinWikiLexer` - - For MoinMoin (and Trac) Wiki markup. - - *New in Pygments 0.7.* - - :Aliases: ``moin``, ``trac-wiki`` - :Filename patterns: None - :Mimetypes: ``text/x-trac-wiki`` +[builtin_lexer_docs] Iterating over all lexers diff --git a/pygments/filters/__init__.py b/pygments/filters/__init__.py index 3f42741f..3bf7d79a 100644 --- a/pygments/filters/__init__.py +++ b/pygments/filters/__init__.py @@ -41,7 +41,10 @@ def get_all_filters(): class CodeTagFilter(Filter): """ - Highlights codetags in comments and docstrings. + Highlights special code tags in comments and docstrings. Per default, the + list of highlighted tags is ``XXX``, ``TODO``, ``BUG`` and ``NOTE``. You can + override this list by specifying a `codetags` parameter that takes a list of + words. """ def __init__(self, **options): Filter.__init__(self) @@ -72,8 +75,11 @@ class CodeTagFilter(Filter): class KeywordCaseFilter(Filter): """ - Changes the case of keywords. (To ``lower``, ``upper`` or - ``capitalize`` case) + Converts keywords to ``lower``, ``upper`` or ``capitalize`` which means + first letter uppercase, rest lowercase. This can be useful e.g. if you + highlight Pascal code and want to adapt the code to your styleguide. The + default is ``lower``, override that by providing the `keywordcase` + parameter. """ def __init__(self, **options): diff --git a/pygments/formatters/__init__.py b/pygments/formatters/__init__.py index be20c0ce..8aefe103 100644 --- a/pygments/formatters/__init__.py +++ b/pygments/formatters/__init__.py @@ -34,18 +34,18 @@ def _doc_desc(obj): FORMATTERS = { HtmlFormatter: ('HTML', ('html',), ('.htm', '.html'), _doc_desc(HtmlFormatter)), - TerminalFormatter: ('Terminal', ('terminal', 'console'), (), - _doc_desc(TerminalFormatter)), LatexFormatter: ('LaTeX', ('latex', 'tex'), ('.tex',), _doc_desc(LatexFormatter)), RtfFormatter: ('RTF', ('rtf',), ('.rtf',), _doc_desc(RtfFormatter)), + TerminalFormatter: ('Terminal', ('terminal', 'console'), (), + _doc_desc(TerminalFormatter)), + BBCodeFormatter: ('BBcode', ('bbcode', 'bb'), (), + _doc_desc(BBCodeFormatter)), RawTokenFormatter: ('Raw tokens', ('raw', 'tokens'), ('.raw',), _doc_desc(RawTokenFormatter)), NullFormatter: ('Text only', ('text', 'null'), ('.txt',), _doc_desc(NullFormatter)), - BBCodeFormatter: ('BBcode', ('bbcode', 'bb'), (), - _doc_desc(BBCodeFormatter)) } diff --git a/pygments/formatters/bbcode.py b/pygments/formatters/bbcode.py index d9b96485..2f15884a 100644 --- a/pygments/formatters/bbcode.py +++ b/pygments/formatters/bbcode.py @@ -18,12 +18,14 @@ __all__ = ['BBCodeFormatter'] class BBCodeFormatter(Formatter): """ - Output BBCode tags with appropiate colors and formatting. + Formats tokens with BBcodes. These formatting codes are used by many + bulletin boards, so you can highlight your sourcecode with pygments before + posting it there. - This formatter doesn't support background colors and borders, as there are - no common BBcodes for that. + This formatter has no support for background colors and borders, as there + are no common BBcode tags for that. - Some board systems (e.g. phpBB) don't support markup in their [code] tag, + Some board systems (e.g. phpBB) don't support colors in their [code] tag, so you can't use the highlighting together with that tag. Text in a [code] tag usually is shown with a monospace font (which this formatter can do with the ``monofont`` option) and no spaces (which you @@ -31,12 +33,13 @@ class BBCodeFormatter(Formatter): Additional options accepted: - ``codetag`` - If set to true, put the output into [code] tags (default: false). + `codetag` + If set to true, put the output into ``[code]`` tags (default: + ``false``) - ``monofont`` + `monofont` If set to true, add a tag to show the code with a monospace font - (default: false). + (default: ``false``). """ def __init__(self, **options): diff --git a/pygments/formatters/html.py b/pygments/formatters/html.py index f72046ef..d323c781 100644 --- a/pygments/formatters/html.py +++ b/pygments/formatters/html.py @@ -103,43 +103,106 @@ td.linenos { background-color: #f0f0f0; padding-right: 10px; } class HtmlFormatter(Formatter): """ - Output HTML <span> tags with appropriate classes. + Format tokens as HTML 4 ``<span>`` tags within a ``<pre>`` tag, wrapped + in a ``<div>`` tag. The ``<div>``'s CSS class can be set by the `cssclass` + option. + + If the `linenos` option is given and true, the ``<pre>`` is additionally + wrapped inside a ``<table>`` which has one row and two cells: one + containing the line numbers and one containing the code. Example: + + .. sourcecode:: html + + <div class="highlight" > + <table><tr> + <td class="linenos" title="click to toggle" + onclick="with (this.firstChild.style) + { display = (display == '') ? 'none' : '' }"> + <pre>1 + 2</pre> + </td> + <td class="code"> + <pre><span class="Ke">def </span><span class="NaFu">foo</span>(bar): + <span class="Ke">pass</span> + </pre> + </td> + </tr></table></div> + + (whitespace added to improve clarity). Wrapping can be disabled using the + `nowrap` option. + + With the `full` option, a complete HTML 4 document is output, including + the style definitions inside a ``<style>`` tag, or in a separate file if + the `cssfile` option is given. + + The `get_style_defs(arg='')` method of a `HtmlFormatter` returns a string + containing CSS rules for the CSS classes used by the formatter. The + argument `arg` can be used to specify additional CSS selectors that + are prepended to the classes. A call `fmter.get_style_defs('td .code')` + would result in the following CSS classes: + + .. sourcecode:: css + + td .code .kw { font-weight: bold; color: #00FF00 } + td .code .cm { color: #999999 } + ... + + If you have pygments 0.6 or higher you can also pass a list of tuple to the + `get_style_defs` method to request multiple prefixes for the tokens: + + .. sourcecode:: python + + formatter.get_style_defs(['div.syntax pre', 'pre.syntax']) + + The output would then look like this: + + .. sourcecode:: css + + div.syntax pre .kw, + pre.syntax .kw { font-weight: bold; color: #00FF00 } + div.syntax pre .cm, + pre.syntax .cm { color: #999999 } + ... Additional options accepted: - ``nowrap`` - If set to true, don't wrap the tokens at all. This disables - all other options (default: False). - ``noclasses`` - If set to true, token <span>s will not use CSS classes, but - inline styles. - ``classprefix`` - Prefix for token CSS classes, is prepended to all token style - classes (e.g. class="o" -> class="_o" if classprefix == '_') - (default: ''). - ``cssclass`` - CSS class for the wrapping <div> (default: 'highlight'). - ``cssstyles`` - Inline CSS styles for the wrapping <div>. (default: ''). - ``cssfile`` - If the ``full`` option is ``True`` and this is not ``''``, - put the CSS in a separate file whose name is given by this option - (default: ''). New in 0.6. - ``linenos`` - If set to ``True``, output line numbers (default: False). - ``linenostart`` - The line number for the first line (default: 1). - ``linenostep`` - If set to a number n > 1, only every nth line number is printed - (default: 1). - ``linenospecial`` - If set to a number n > 0, every nth line number is given a special - CSS class ``special`` (default: 0). - ``nobackground`` - If set to ``True`` the formatter won't output the background color - for the overall element (this automatically defaults to ``False`` - when there is no overall element [eg: no argument for the - `get_syntax_defs` method given]) (default: ``False``). New in 0.6. + `nowrap` + If set to ``True``, don't wrap the tokens at all, not even in a ``<pre>`` + tag. This disables all other options (default: ``False``). + + `noclasses` + If set to true, token ``<span>`` tags will not use CSS classes, but + inline styles. This is not recommended for larger pieces of code since + it increases output size by quite a bit (default: ``False``). + + `classprefix` + Since the token types use relatively short class names, they may clash + with some of your own class names. In this case you can use the + `classprefix` option to give a string to prepend to all Pygments-generated + CSS class names for token types. + Note that this option also affects the output of `get_style_defs()`. + + `cssclass` + CSS class for the wrapping ``<div>`` tag (default: ``'highlight'``). + + `cssstyles` + Inline CSS styles for the wrapping ``<div>`` tag (default: ``''``). + + `cssfile` + If the `full` option is true and this option is given, it must be the + name of an external file. The stylesheet is then written to this file + instead of the HTML file. *New in Pygments 0.6.* + + `linenospecial` + If set to a number n > 0, every nth line number is given the CSS + class ``"special"`` (default: ``0``). + + `nobackground` + If set to ``True``, the formatter won't output the background color + for the wrapping element (this automatically defaults to ``False`` + when there is no wrapping element [eg: no argument for the + `get_syntax_defs` method given]) (default: ``False``). *New in + Pygments 0.6.* """ def __init__(self, **options): diff --git a/pygments/formatters/latex.py b/pygments/formatters/latex.py index d3d4f0b5..d8bdb8a3 100644 --- a/pygments/formatters/latex.py +++ b/pygments/formatters/latex.py @@ -46,32 +46,48 @@ DOC_TEMPLATE = r''' class LatexFormatter(Formatter): - """ - Output LaTeX "color" and "fancyvrb" control sequences. + r""" + Format tokens as LaTeX code. This needs the `fancyvrb` and `color` + standard packages. + + Without the `full` option, code is formatted as one ``Verbatim`` + environment, like this: + + .. sourcecode:: latex + + \begin{Verbatim}[commandchars=@\[\]] + @Can[def ]@Cax[foo](bar): + @Can[pass] + \end{Verbatim} + + The command sequences used here (``@Can`` etc.) are generated from the given + `style` and can be retrieved using the `get_style_defs` method. + + With the `full` option, a complete LaTeX document is output, including + the command definitions in the preamble. + + The `get_style_defs(arg='')` method of a `LatexFormatter` returns a string + containing ``\newcommand`` commands defining the commands used inside the + ``Verbatim`` environments. If the argument `arg` is true, + ``\renewcommand`` is used instead. + + Additional options accepted: + + `docclass` + If the `full` option is enabled, this is the document class to use + (default: ``'article'``). + + `preamble` + If the `full` option is enabled, this can be further preamble commands, + e.g. ``\usepackage`` (default: ``''``). + + `verboptions` + Additional options given to the Verbatim environment (see the *fancyvrb* + docs for possible values) (default: ``''``). + """ def __init__(self, **options): - """ - Additional options accepted: - - ``docclass`` - If ``full`` is true, this is the document class to use (default: 'article'). - ``preamble`` - If ``full`` is true, this can be further preamble commands (default: ''). - ``linenos`` - If true, output line numbers (default: False). - ``linenostart`` - The line number for the first line (default: 1). - ``linenostep`` - If set to a number n > 1, only every nth line number is printed (default: 1). - ``verboptions`` - Additional options given to the Verbatim environment (default: ''). - ``nobackground`` - If set to ``True`` the formatter won't output the background color - for the overall element (default: ``False``) - Note that light colors on dark background with this option disabled - won't be readable very good. - """ Formatter.__init__(self, **options) self.docclass = options.get('docclass', 'article') self.preamble = options.get('preamble', '') diff --git a/pygments/formatters/other.py b/pygments/formatters/other.py index f6101848..7ef39b4f 100644 --- a/pygments/formatters/other.py +++ b/pygments/formatters/other.py @@ -29,16 +29,18 @@ class NullFormatter(Formatter): class RawTokenFormatter(Formatter): - """ - Output a raw token representation for storing token streams. + r""" + Formats tokens as a raw representation for storing token streams. - The format is ``tokentype<TAB>repr(tokenstring)`` + The format is ``tokentype<TAB>repr(tokenstring)\n``. The output can later + be converted to a token stream with the `RawTokenLexer`, described in the + `lexer list <lexers.txt>`_. - Additional options accepted: + Only one option is accepted: - ``compress`` - If set to "gz" or "bz2", compress the token stream with - the given compression algorithm (default: ''). + `compress` + If set to ``'gz'`` or ``'bz2'``, compress the output with the given + compression algorithm after encoding (default: ``''``). """ unicodeoutput = False diff --git a/pygments/formatters/rtf.py b/pygments/formatters/rtf.py index f6764d50..9bfed9d8 100644 --- a/pygments/formatters/rtf.py +++ b/pygments/formatters/rtf.py @@ -16,7 +16,19 @@ __all__ = ['RtfFormatter'] class RtfFormatter(Formatter): - """Output RTF (Rich Text Format).""" + """ + Formats tokens as RTF markup. This formatter automatically outputs full RTF + documents with color information and other useful stuff. Perfect for Copy and + Paste into Microsoft® Word® documents. + + *New in Pygments 0.6.* + + Additional options accepted: + + `fontface` + The used font famliy, for example ``Bitstream Vera Sans``. Defaults to + some generic font which is supposed to have fixed width. + """ unicodeoutput = False diff --git a/pygments/formatters/terminal.py b/pygments/formatters/terminal.py index 4d6debd9..661031e7 100644 --- a/pygments/formatters/terminal.py +++ b/pygments/formatters/terminal.py @@ -51,22 +51,26 @@ TERMINAL_COLORS = { class TerminalFormatter(Formatter): - """ - Output plain text with coloring ANSI sequences. - """ + r""" + Formats tokens with ANSI color sequences, for output in a text console. + Color sequences are terminated at newlines, so that paging the output + works correctly. - def __init__(self, **options): - """ - Accepted options: + The `get_style_defs()` method doesn't do anything special since there is + no support for common styles. + + Options accepted: - ``bg`` - Set to ``'light'`` or ``'dark'`` depending on the - terminal's background. + `bg` + Set to ``"light"`` or ``"dark"`` depending on the terminal's background + (default: ``"light"``). - ``colorscheme`` - ``None`` or a dictionary mapping token types to - ``(lightbg, darkbg)`` color names. - """ + `colorscheme` + A dictionary mapping token types to (lightbg, darkbg) color names or + ``None`` (default: ``None`` = use builtin colorscheme). + """ + + def __init__(self, **options): Formatter.__init__(self, **options) self.darkbg = options.get('bg', 'light') == 'dark' self.colorscheme = options.get('colorscheme', None) or TERMINAL_COLORS diff --git a/pygments/lexers/agile.py b/pygments/lexers/agile.py index 7337b323..7275ea28 100644 --- a/pygments/lexers/agile.py +++ b/pygments/lexers/agile.py @@ -3,7 +3,7 @@ pygments.lexers.agile ~~~~~~~~~~~~~~~~~~~~~ - Lexers for agile languages: Python, Ruby, Perl, Scheme. + Lexers for agile languages. :copyright: 2006 by Georg Brandl, Armin Ronacher, Lukas Meuser, Marek Kubica, Tim Hatch. @@ -31,6 +31,10 @@ line_re = re.compile('.*?\n') class PythonLexer(RegexLexer): + """ + For `Python <http://www.python.org>`_ source code. + """ + name = 'Python' aliases = ['python', 'py'] filenames = ['*.py', '*.pyw'] @@ -156,11 +160,17 @@ class PythonLexer(RegexLexer): class PythonConsoleLexer(Lexer): """ - Parses Python console output or doctests, like:: + For Python console output or doctests, such as: + + .. sourcecode:: pycon - >>> a = 1 + >>> a = 'foo' >>> print a - 1 + foo + >>> 1 / 0 + Traceback (most recent call last): + File "<stdin>", line 1, in <module> + ZeroDivisionError: integer division or modulo by zero """ name = 'Python console session' aliases = ['pycon'] @@ -207,6 +217,12 @@ class PythonConsoleLexer(Lexer): class PythonTracebackLexer(RegexLexer): + """ + For Python tracebacks. + + *New in Pygments 0.7.* + """ + name = 'PythonTraceback' aliases = ['pytb'] filenames = ['*.pytb'] @@ -228,6 +244,10 @@ class PythonTracebackLexer(RegexLexer): class RubyLexer(ExtendedRegexLexer): + """ + For `Ruby <http://www.ruby-lang.org>`_ source code. + """ + name = 'Ruby' aliases = ['rb', 'ruby'] filenames = ['*.rb', '*.rbw', 'Rakefile', '*.rake', '*.gemspec', '*.rbx'] @@ -542,7 +562,9 @@ class RubyLexer(ExtendedRegexLexer): class RubyConsoleLexer(Lexer): """ - Parses Ruby console output like:: + For Ruby interactive console (**irb**) output like: + + .. sourcecode:: rbcon irb(main):001:0> a = 1 => 1 @@ -583,6 +605,10 @@ class RubyConsoleLexer(Lexer): class PerlLexer(RegexLexer): + """ + For `Perl <http://www.perl.org>`_ source code. + """ + name = 'Perl' aliases = ['perl', 'pl'] filenames = ['*.pl', '*.pm'] @@ -717,6 +743,28 @@ class PerlLexer(RegexLexer): class LuaLexer(RegexLexer): + """ + For `Lua <http://www.lua.org>`_ source code. + + Additional options accepted: + + `func_name_highlighting` + If given and ``True``, highlight builtin function names + (default: ``True``). + `disabled_modules` + If given, must be a list of module names whose function names + should not be highlighted. By default all modules are highlighted. + + To get a list of allowed modules have a look into the + `_luabuiltins` module: + + .. sourcecode:: pycon + + >>> from pygments.lexers._luabuiltins import MODULES + >>> MODULES.keys() + ['string', 'coroutine', 'modules', 'io', 'basic', ...] + """ + name = 'Lua' aliases = ['lua'] filenames = ['*.lua'] @@ -824,7 +872,9 @@ class SchemeLexer(RegexLexer): This parser is checked with pastes from the LISP pastebin at http://paste.lisp.org/ to cover as much syntax as possible. - It should support the full Scheme syntax as defined in R5RS. + It supports the full Scheme syntax as defined in R5RS. + + *New in Pygments 0.6.* """ name = 'Scheme' aliases = ['scheme'] diff --git a/pygments/lexers/compiled.py b/pygments/lexers/compiled.py index 5de1cf71..36d80d66 100644 --- a/pygments/lexers/compiled.py +++ b/pygments/lexers/compiled.py @@ -3,7 +3,7 @@ pygments.lexers.compiled ~~~~~~~~~~~~~~~~~~~~~~~~ - Lexers for compiled languages: C/C++, Delphi, Java. + Lexers for compiled languages. :copyright: 2006 by Georg Brandl, Armin Ronacher, Christoph Hack. :license: BSD, see LICENSE for more details. @@ -28,6 +28,9 @@ __all__ = ['CLexer', 'CppLexer', 'DelphiLexer', 'JavaLexer'] class CLexer(RegexLexer): + """ + For C source code with preprocessor directives. + """ name = 'C' aliases = ['c'] filenames = ['*.c', '*.h'] @@ -122,6 +125,9 @@ class CLexer(RegexLexer): class CppLexer(RegexLexer): + """ + For C++ source code with preprocessor directives. + """ name = 'C++' aliases = ['cpp', 'c++'] filenames = ['*.cpp', '*.hpp', '*.c++', '*.h++'] @@ -196,6 +202,23 @@ class CppLexer(RegexLexer): class DelphiLexer(Lexer): + """ + For `Delphi <http://www.borland.com/delphi/>`_ (Borland Object Pascal), + Turbo Pascal and Free Pascal source code. + + Additional options accepted: + + `turbopascal` + Highlight Turbo Pascal specific keywords (default: ``True``). + `delphi` + Highlight Borland Delphi specific keywords (default: ``True``). + `freepascal` + Highlight Free Pascal specific keywords (default: ``True``). + `units` + A list of units that should be considered builtin, supported are + ``System``, ``SysUtils``, ``Classes`` and ``Math``. + Default is to consider all of them builtin. + """ name = 'Delphi' aliases = ['delphi', 'pas', 'pascal', 'objectpascal'] filenames = ['*.pas'] @@ -663,6 +686,10 @@ class DelphiLexer(Lexer): class JavaLexer(RegexLexer): + """ + For `Java <http://www.sun.com/java/>`_ source code. + """ + name = 'Java' aliases = ['java'] filenames = ['*.java'] diff --git a/pygments/lexers/dotnet.py b/pygments/lexers/dotnet.py index c8b278d8..f47532ba 100644 --- a/pygments/lexers/dotnet.py +++ b/pygments/lexers/dotnet.py @@ -3,7 +3,7 @@ pygments.lexers.dotnet ~~~~~~~~~~~~~~~~~~~~~~ - .net languages + Lexers for .net languages. :copyright: 2006 by Georg Brandl, Armin Ronacher. :license: BSD, see LICENSE for more details. @@ -18,6 +18,11 @@ __all__ = ['CSharpLexer', 'BooLexer', 'VbNetLexer'] class CSharpLexer(RegexLexer): + """ + For `C# <http://msdn2.microsoft.com/en-us/vcsharp/default.aspx>`_ + source code. + """ + name = 'C#' aliases = ['csharp', 'c#'] filenames = ['*.cs'] @@ -75,6 +80,10 @@ class CSharpLexer(RegexLexer): class BooLexer(RegexLexer): + """ + For `Boo <http://boo.codehaus.org/>`_ source code. + """ + name = 'Boo' aliases = ['boo'] filenames = ['*.boo'] @@ -138,6 +147,12 @@ class BooLexer(RegexLexer): class VbNetLexer(RegexLexer): + """ + For + `Visual Basic.NET <http://msdn2.microsoft.com/en-us/vbasic/default.aspx>`_ + source code. + """ + name = 'VB.net' aliases = ['vb.net', 'vbnet'] filenames = ['*.vb', '*.bas'] diff --git a/pygments/lexers/other.py b/pygments/lexers/other.py index cede911f..cec162b4 100644 --- a/pygments/lexers/other.py +++ b/pygments/lexers/other.py @@ -3,7 +3,7 @@ pygments.lexers.other ~~~~~~~~~~~~~~~~~~~~~ - Lexers for other languages: SQL, BrainFuck. + Lexers for other languages. :copyright: 2006 by Georg Brandl, Tim Hatch <tim@timhatch.com>. :license: BSD, see LICENSE for more details. @@ -21,6 +21,11 @@ __all__ = ['SqlLexer', 'BrainfuckLexer', 'BashLexer'] class SqlLexer(RegexLexer): + """ + Lexer for Structured Query Language. Currently, this lexer does + not recognize any special syntax except ANSI SQL. + """ + name = 'SQL' aliases = ['sql'] filenames = ['*.sql'] @@ -130,6 +135,11 @@ class SqlLexer(RegexLexer): class BrainfuckLexer(RegexLexer): + """ + Lexer for the esoteric `BrainFuck <http://www.muppetlabs.com/~breadbox/bf/>`_ + language. + """ + name = 'Brainfuck' aliases = ['brainfuck', 'bf'] filenames = ['*.bf', '*.b'] @@ -157,8 +167,11 @@ class BrainfuckLexer(RegexLexer): class BashLexer(RegexLexer): """ - Lex (ba)sh source files. + Lexer for (ba)sh shell scripts. + + *New in Pygments 0.6.* """ + name = 'Bash' aliases = ['bash', 'sh'] filenames = ['*.sh'] diff --git a/pygments/lexers/special.py b/pygments/lexers/special.py index 5af9320a..8cd43246 100644 --- a/pygments/lexers/special.py +++ b/pygments/lexers/special.py @@ -20,6 +20,9 @@ __all__ = ['TextLexer', 'RawTokenLexer'] class TextLexer(Lexer): + """ + "Null" lexer, doesn't highlight anything. + """ name = 'Text only' aliases = ['text'] filenames = ['*.txt'] @@ -35,13 +38,13 @@ line_re = re.compile('.*?\n') class RawTokenLexer(Lexer): """ - Recreate a token stream formatted with the RawTokenFormatter. + Recreate a token stream formatted with the `RawTokenFormatter`. Additional options accepted: - ``compress`` - If set to "gz" or "bz2", decompress the token stream with - the given compression algorithm (default: ''). + `compress` + If set to ``"gz"`` or ``"bz2"``, decompress the token stream with + the given compression algorithm before lexing (default: ``''``). """ name = 'Raw token data' aliases = ['raw'] diff --git a/pygments/lexers/templates.py b/pygments/lexers/templates.py index 3efb3ba5..7c8c356d 100644 --- a/pygments/lexers/templates.py +++ b/pygments/lexers/templates.py @@ -3,7 +3,7 @@ pygments.lexers.templates ~~~~~~~~~~~~~~~~~~~~~~~~~ - Lexers for various template engines. + Lexers for various template engines' markup. :copyright: 2006 by Armin Ronacher, Georg Brandl, Matt Good, Ben Bangert. @@ -40,6 +40,16 @@ __all__ = ['HtmlPhpLexer', 'XmlPhpLexer', 'CssPhpLexer', class ErbLexer(Lexer): + """ + Generic `ERB <http://ruby-doc.org/core/classes/ERB.html>`_ (Ruby Templating) + lexer. + + Just highlights ruby code between the preprocessor directives, other data + is left untouched by the lexer. + + All options are also forwarded to the `RubyLexer`. + """ + name = 'ERB' aliases = ['erb'] @@ -124,6 +134,13 @@ class ErbLexer(Lexer): class SmartyLexer(RegexLexer): + """ + Generic `Smarty <http://smarty.php.net/>`_ template lexer. + + Just highlights smarty code between the preprocessor directives, other + data is left untouched by the lexer. + """ + name = 'Smarty' aliases = ['smarty'] filenames = ['*.tpl'] @@ -171,6 +188,14 @@ class SmartyLexer(RegexLexer): class DjangoLexer(RegexLexer): + """ + Generic `django <http://www.djangoproject.com/documentation/templates/>`_ + and `jinja <http://wsgiarea.pocoo.org/jinja/>`_ template lexer. + + It just highlights django/jinja code between the preprocessor directives, + other data is left untouched by the lexer. + """ + name = 'Django/Jinja' aliases = ['django', 'jinja'] @@ -227,6 +252,15 @@ class DjangoLexer(RegexLexer): class MyghtyLexer(RegexLexer): + """ + Generic `myghty templates`_ lexer. Code that isn't Myghty + markup is yielded as `Token.Other`. + + *New in Pygments 0.6.* + + .. _myghty templates: http://www.myghty.org/ + """ + name = 'Myghty' aliases = ['myghty'] filenames = ['*.myt', 'autodelegate'] @@ -250,22 +284,28 @@ class MyghtyLexer(RegexLexer): (r'(?<=^)\#[^\n]*(\n|\Z)', Comment), (r'(?<=^)(\%)([^\n]*)(\n|\Z)', bygroups(Name.Tag, using(PythonLexer), Other)), - (r'''(?sx) - (.+?) # anything, followed by: - (?: - (?<=\n)(?=[%#]) | # an eval or comment line - (?=</?[%&]) | # a substitution or block or - # call start or end - # - don't consume - (\\\n) | # an escaped newline - \Z # end of string - ) - ''', bygroups(Other, Operator)), + (r"""(?sx) + (.+?) # anything, followed by: + (?: + (?<=\n)(?=[%#]) | # an eval or comment line + (?=</?[%&]) | # a substitution or block or + # call start or end + # - don't consume + (\\\n) | # an escaped newline + \Z # end of string + )""", bygroups(Other, Operator)), ] } class MyghtyHtmlLexer(DelegatingLexer): + """ + Subclass of the `MyghtyLexer` that highlights unlexer data + with the `HtmlLexer`. + + *New in Pygments 0.6.* + """ + name = 'HTML+Myghty' aliases = ['html+myghty'] @@ -275,6 +315,13 @@ class MyghtyHtmlLexer(DelegatingLexer): class MyghtyXmlLexer(DelegatingLexer): + """ + Subclass of the `MyghtyLexer` that highlights unlexer data + with the `XmlLexer`. + + *New in Pygments 0.6.* + """ + name = 'XML+Myghty' aliases = ['xml+myghty'] @@ -284,6 +331,13 @@ class MyghtyXmlLexer(DelegatingLexer): class MyghtyJavascriptLexer(DelegatingLexer): + """ + Subclass of the `MyghtyLexer` that highlights unlexer data + with the `JavascriptLexer`. + + *New in Pygments 0.6.* + """ + name = 'JavaScript+Myghty' aliases = ['js+myghty', 'javascript+myghty'] @@ -293,6 +347,13 @@ class MyghtyJavascriptLexer(DelegatingLexer): class MyghtyCssLexer(DelegatingLexer): + """ + Subclass of the `MyghtyLexer` that highlights unlexer data + with the `CssLexer`. + + *New in Pygments 0.6.* + """ + name = 'CSS+Myghty' aliases = ['css+myghty'] @@ -302,6 +363,15 @@ class MyghtyCssLexer(DelegatingLexer): class MakoLexer(RegexLexer): + """ + Generic `mako templates`_ lexer. Code that isn't Mako + markup is yielded as `Token.Other`. + + *New in Pygments 0.7.* + + .. _mako templates: http://www.makotemplates.org/ + """ + name = 'Mako' aliases = ['mako'] filenames = ['*.mao'] @@ -358,6 +428,13 @@ class MakoLexer(RegexLexer): class MakoHtmlLexer(DelegatingLexer): + """ + Subclass of the `MakoLexer` that highlights unlexed data + with the `HtmlLexer`. + + *New in Pygments 0.7.* + """ + name = 'HTML+Mako' aliases = ['html+mako'] @@ -366,6 +443,13 @@ class MakoHtmlLexer(DelegatingLexer): **options) class MakoXmlLexer(DelegatingLexer): + """ + Subclass of the `MakoLexer` that highlights unlexer data + with the `XmlLexer`. + + *New in Pygments 0.7.* + """ + name = 'XML+Mako' aliases = ['xml+mako'] @@ -374,6 +458,13 @@ class MakoXmlLexer(DelegatingLexer): **options) class MakoJavascriptLexer(DelegatingLexer): + """ + Subclass of the `MakoLexer` that highlights unlexer data + with the `JavascriptLexer`. + + *New in Pygments 0.7.* + """ + name = 'JavaScript+Mako' aliases = ['js+mako', 'javascript+mako'] @@ -382,6 +473,13 @@ class MakoJavascriptLexer(DelegatingLexer): MakoLexer, **options) class MakoCssLexer(DelegatingLexer): + """ + Subclass of the `MakoLexer` that highlights unlexer data + with the `CssLexer`. + + *New in Pygments 0.7.* + """ + name = 'CSS+Mako' aliases = ['css+mako'] @@ -393,6 +491,11 @@ class MakoCssLexer(DelegatingLexer): # Genshi lexers courtesy of Matt Good. class GenshiTextLexer(RegexLexer): + """ + A lexer that highlights `genshi <http://genshi.edgewall.org/>`_ text + templates. + """ + name = 'Genshi Text' aliases = ['genshitext'] @@ -422,6 +525,11 @@ class GenshiTextLexer(RegexLexer): class GenshiMarkupLexer(RegexLexer): + """ + Base lexer for Genshi markup, used by `HtmlGenshiLexer` and + `GenshiLexer`. + """ + flags = re.DOTALL tokens = { @@ -481,6 +589,11 @@ class GenshiMarkupLexer(RegexLexer): class HtmlGenshiLexer(DelegatingLexer): + """ + A lexer that highlights `genshi <http://genshi.edgewall.org/>`_ and + `kid <http://kid-templating.org/>`_ kid HTML templates. + """ + name = 'HTML+Genshi' aliases = ['html+genshi', 'html+kid'] alias_filenames = ['*.html', '*.htm', '*.xhtml'] @@ -499,6 +612,11 @@ class HtmlGenshiLexer(DelegatingLexer): class GenshiLexer(DelegatingLexer): + """ + A lexer that highlights `genshi <http://genshi.edgewall.org/>`_ and + `kid <http://kid-templating.org/>`_ kid XML templates. + """ + name = 'Genshi' aliases = ['genshi', 'kid', 'xml+genshi', 'xml+kid'] filenames = ['*.kid'] @@ -518,6 +636,10 @@ class GenshiLexer(DelegatingLexer): class JavascriptGenshiLexer(DelegatingLexer): + """ + A lexer that highlights javascript code in genshi text templates. + """ + name = 'JavaScript+Genshi Text' aliases = ['js+genshitext', 'js+genshi', 'javascript+genshitext', 'javascript+genshi'] @@ -533,6 +655,10 @@ class JavascriptGenshiLexer(DelegatingLexer): class CssGenshiLexer(DelegatingLexer): + """ + A lexer that highlights CSS definitions in genshi text templates. + """ + name = 'CSS+Genshi Text' aliases = ['css+genshitext', 'css+genshi'] alias_filenames = ['*.css'] @@ -546,6 +672,13 @@ class CssGenshiLexer(DelegatingLexer): class RhtmlLexer(DelegatingLexer): + """ + Subclass of the ERB lexer that highlights the unlexed data with the + html lexer. + + Nested Javascript and CSS is highlighted too. + """ + name = 'RHTML' aliases = ['rhtml', 'html+erb', 'html+ruby'] filenames = ['*.rhtml'] @@ -563,6 +696,11 @@ class RhtmlLexer(DelegatingLexer): class XmlErbLexer(DelegatingLexer): + """ + Subclass of `ErbLexer` which highlights data outside preprocessor + directives with the `XmlLexer`. + """ + name = 'XML+Ruby' aliases = ['xml+erb', 'xml+ruby'] alias_filenames = ['*.xml'] @@ -578,6 +716,10 @@ class XmlErbLexer(DelegatingLexer): class CssErbLexer(DelegatingLexer): + """ + Subclass of `ErbLexer` which highlights unlexed data with the `CssLexer`. + """ + name = 'CSS+Ruby' aliases = ['css+erb', 'css+ruby'] alias_filenames = ['*.xml'] @@ -590,6 +732,11 @@ class CssErbLexer(DelegatingLexer): class JavascriptErbLexer(DelegatingLexer): + """ + Subclass of `ErbLexer` which highlights unlexed data with the + `JavascriptLexer`. + """ + name = 'JavaScript+Ruby' aliases = ['js+erb', 'javascript+erb', 'js+ruby', 'javascript+ruby'] alias_filenames = ['*.js'] @@ -603,6 +750,12 @@ class JavascriptErbLexer(DelegatingLexer): class HtmlPhpLexer(DelegatingLexer): + """ + Subclass of `PhpLexer` that highlights unhandled data with the `HtmlLexer`. + + Nested Javascript and CSS is highlighted too. + """ + name = 'HTML+PHP' aliases = ['html+php'] filenames = ['*.phtml'] @@ -623,6 +776,10 @@ class HtmlPhpLexer(DelegatingLexer): class XmlPhpLexer(DelegatingLexer): + """ + Subclass of `PhpLexer` that higlights unhandled data with the `XmlLexer`. + """ + name = 'XML+PHP' aliases = ['xml+php'] alias_filenames = ['*.xml', '*.php', '*.php[345]'] @@ -638,6 +795,10 @@ class XmlPhpLexer(DelegatingLexer): class CssPhpLexer(DelegatingLexer): + """ + Subclass of `PhpLexer` which highlights unmatched data with the `CssLexer`. + """ + name = 'CSS+PHP' aliases = ['css+php'] alias_filenames = ['*.css'] @@ -650,6 +811,11 @@ class CssPhpLexer(DelegatingLexer): class JavascriptPhpLexer(DelegatingLexer): + """ + Subclass of `PhpLexer` which highlights unmatched data with the + `JavascriptLexer`. + """ + name = 'JavaScript+PHP' aliases = ['js+php', 'javascript+php'] alias_filenames = ['*.js'] @@ -663,6 +829,13 @@ class JavascriptPhpLexer(DelegatingLexer): class HtmlSmartyLexer(DelegatingLexer): + """ + Subclass of the `SmartyLexer` that highighlights unlexed data with the + `HtmlLexer`. + + Nested Javascript and CSS is highlighted too. + """ + name = 'HTML+Smarty' aliases = ['html+smarty'] alias_filenames = ['*.html', '*.htm', '*.xhtml', '*.tpl'] @@ -678,6 +851,11 @@ class HtmlSmartyLexer(DelegatingLexer): class XmlSmartyLexer(DelegatingLexer): + """ + Subclass of the `SmartyLexer` that highlights unlexed data with the + `XmlLexer`. + """ + name = 'XML+Smarty' aliases = ['xml+smarty'] alias_filenames = ['*.xml', '*.tpl'] @@ -693,6 +871,11 @@ class XmlSmartyLexer(DelegatingLexer): class CssSmartyLexer(DelegatingLexer): + """ + Subclass of the `SmartyLexer` that highlights unlexed data with the + `CssLexer`. + """ + name = 'CSS+Smarty' aliases = ['css+smarty'] alias_filenames = ['*.css', '*.tpl'] @@ -705,6 +888,11 @@ class CssSmartyLexer(DelegatingLexer): class JavascriptSmartyLexer(DelegatingLexer): + """ + Subclass of the `SmartyLexer` that highlights unlexed data with the + `JavascriptLexer`. + """ + name = 'JavaScript+Smarty' aliases = ['js+smarty', 'javascript+smarty'] alias_filenames = ['*.js', '*.tpl'] @@ -718,6 +906,13 @@ class JavascriptSmartyLexer(DelegatingLexer): class HtmlDjangoLexer(DelegatingLexer): + """ + Subclass of the `DjangoLexer` that highighlights unlexed data with the + `HtmlLexer`. + + Nested Javascript and CSS is highlighted too. + """ + name = 'HTML+Django/Jinja' aliases = ['html+django', 'html+jinja'] alias_filenames = ['*.html', '*.htm', '*.xhtml'] @@ -733,6 +928,11 @@ class HtmlDjangoLexer(DelegatingLexer): class XmlDjangoLexer(DelegatingLexer): + """ + Subclass of the `DjangoLexer` that highlights unlexed data with the + `XmlLexer`. + """ + name = 'XML+Django/Jinja' aliases = ['xml+django', 'xml+jinja'] alias_filenames = ['*.xml'] @@ -748,6 +948,11 @@ class XmlDjangoLexer(DelegatingLexer): class CssDjangoLexer(DelegatingLexer): + """ + Subclass of the `DjangoLexer` that highlights unlexed data with the + `CssLexer`. + """ + name = 'CSS+Django/Jinja' aliases = ['css+django', 'css+jinja'] alias_filenames = ['*.css'] @@ -760,6 +965,11 @@ class CssDjangoLexer(DelegatingLexer): class JavascriptDjangoLexer(DelegatingLexer): + """ + Subclass of the `DjangoLexer` that highlights unlexed data with the + `JavascriptLexer`. + """ + name = 'JavaScript+Django/Jinja' aliases = ['js+django', 'javascript+django', 'js+jinja', 'javascript+jinja'] diff --git a/pygments/lexers/text.py b/pygments/lexers/text.py index adee57e4..ba03ff01 100644 --- a/pygments/lexers/text.py +++ b/pygments/lexers/text.py @@ -3,7 +3,7 @@ pygments.lexers.text ~~~~~~~~~~~~~~~~~~~~ - Lexers for non-source code file types: Diff, Makefiles, Ini configs etc. + Lexers for non-source code file types. :copyright: 2006 by Armin Ronacher, Georg Brandl, Tim Hatch <tim@timhatch.com>, @@ -29,6 +29,10 @@ __all__ = ['IniLexer', 'SourcesListLexer', 'MakefileLexer', 'DiffLexer', class IniLexer(RegexLexer): + """ + Lexer for configuration files in INI style. + """ + name = 'INI' aliases = ['ini', 'cfg'] filenames = ['*.ini', '*.cfg'] @@ -52,8 +56,11 @@ class IniLexer(RegexLexer): class SourcesListLexer(RegexLexer): """ - Lex debian sources.list files + Lexer that highlights debian sources.list files. + + *New in Pygments 0.7.* """ + name= 'Debian Sourcelist' aliases = ['sourceslist', 'sources.list'] filenames = ['sources.list'] @@ -97,6 +104,10 @@ class SourcesListLexer(RegexLexer): class MakefileLexer(RegexLexer): + """ + Lexer for Makefiles. + """ + name = 'Makefile' aliases = ['make', 'makefile', 'mf'] filenames = ['*.mak', 'Makefile', 'makefile'] @@ -140,6 +151,10 @@ class MakefileLexer(RegexLexer): class DiffLexer(RegexLexer): + """ + Lexer for unified or context-style diffs or patches. + """ + name = 'Diff' aliases = ['diff'] filenames = ['*.diff', '*.patch'] @@ -168,6 +183,10 @@ class DiffLexer(RegexLexer): class IrcLogsLexer(RegexLexer): + """ + Lexer for IRC logs in **irssi** or **xchat** style. + """ + name = 'IRC logs' aliases = ['irc'] @@ -208,6 +227,12 @@ class IrcLogsLexer(RegexLexer): class BBCodeLexer(RegexLexer): + """ + A lexer that highlights BBCode(-like) syntax. + + *New in Pygments 0.6.* + """ + name = 'BBCode' aliases = ['bbcode'] @@ -223,6 +248,10 @@ class BBCodeLexer(RegexLexer): class TexLexer(RegexLexer): + """ + Lexer for the TeX and LaTeX typesetting languages. + """ + name = 'TeX' aliases = ['tex', 'latex'] filenames = ['*.tex', '*.aux', '*.toc'] @@ -277,9 +306,12 @@ class TexLexer(RegexLexer): class GroffLexer(RegexLexer): """ - Lexer for the roff format, supporting groff extensions. Mainly useful - for highlighting manpages. + Lexer for the (g)roff typesetting language, supporting groff + extensions. Mainly useful for highlighting manpage sources. + + *New in Pygments 0.6.* """ + name = 'Groff' aliases = ['groff', 'nroff', 'man'] filenames = ['*.[1234567]', '*.man'] @@ -329,8 +361,12 @@ class GroffLexer(RegexLexer): class ApacheConfLexer(RegexLexer): """ - Lex Apache configuration like files. + Lexer for configuration files following the Apache config file + format. + + *New in Pygments 0.6.* """ + name = 'ApacheConf' aliases = ['apacheconf', 'aconf', 'apache'] filenames = ['.htaccess', 'apache.conf', 'apache2.conf'] @@ -361,6 +397,12 @@ class ApacheConfLexer(RegexLexer): class MoinWikiLexer(RegexLexer): + """ + For MoinMoin (and Trac) Wiki markup. + + *New in Pygments 0.7.* + """ + name = 'MoinMoin/Trac Wiki markup' aliases = ['trac-wiki', 'moin'] filenames = [] diff --git a/pygments/lexers/web.py b/pygments/lexers/web.py index 9ae674cb..09374209 100644 --- a/pygments/lexers/web.py +++ b/pygments/lexers/web.py @@ -3,7 +3,7 @@ pygments.lexers.web ~~~~~~~~~~~~~~~~~~~ - Lexers for web-related languages: JavaScript, CSS, HTML, XML, PHP. + Lexers for web-related languages and markup. :copyright: 2006 by Georg Brandl, Armin Ronacher, Tim Hatch <tim@timhatch.com>. @@ -28,6 +28,10 @@ __all__ = ['HtmlLexer', 'XmlLexer', 'JavascriptLexer', 'CssLexer', class JavascriptLexer(RegexLexer): + """ + For JavaScript source code. + """ + name = 'JavaScript' aliases = ['js', 'javascript'] filenames = ['*.js'] @@ -61,6 +65,10 @@ class JavascriptLexer(RegexLexer): class CssLexer(RegexLexer): + """ + For CSS (Cascading Style Sheets). + """ + name = 'CSS' aliases = ['css'] filenames = ['*.css'] @@ -190,6 +198,11 @@ class CssLexer(RegexLexer): class HtmlLexer(RegexLexer): + """ + For HTML 4 and XHTML 1 markup. Nested JavaScript and CSS is highlighted + by the appropriate lexer. + """ + name = 'HTML' aliases = ['html'] filenames = ['*.html', '*.htm', '*.xhtml'] @@ -240,6 +253,37 @@ class HtmlLexer(RegexLexer): class PhpLexer(RegexLexer): + """ + For `PHP <http://www.php.net/>`_ source code. + For PHP embedded in HTML, use the `HtmlPhpLexer`. + + Additional options accepted: + + `startinline` + If given and ``True`` the lexer starts highlighting with + php code. (i.e.: no starting ``<?php`` required) + `funcnamehighlighting` + If given and ``True``, highlight builtin function names + (default: ``True``). + `disabledmodules` + If given, must be a list of module names whose function names + should not be highlighted. By default all modules are highlighted + except the special ``'unknown'`` module that includes functions + that are known to php but are undocumented. + + To get a list of allowed modules have a look into the + `_phpbuiltins` module: + + .. sourcecode:: pycon + + >>> from pygments.lexers._phpbuiltins import MODULES + >>> MODULES.keys() + ['PHP Options/Info', 'Zip', 'dba', ...] + + In fact the names of those modules match the module names from + the php documentation. + """ + name = 'PHP' aliases = ['php', 'php3', 'php4', 'php5'] filenames = ['*.php', '*.php[345]'] @@ -349,6 +393,10 @@ class PhpLexer(RegexLexer): class XmlLexer(RegexLexer): + """ + Generic lexer for XML (eXtensible Markup Language). + """ + flags = re.MULTILINE | re.DOTALL name = 'XML' |