# HG changeset patch # User cmlenz # Date 1181127768 0 # Node ID 4525549aa6cc16bb10bcb4c352ad83e8b1bff847 # Parent 3b314a78015d184ca7cddb0bac56fc7880f6bd3d Syntax highlighting for the docs. diff --git a/doc/catalogs.txt b/doc/catalogs.txt --- a/doc/catalogs.txt +++ b/doc/catalogs.txt @@ -15,11 +15,15 @@ The ``gettext`` translation system enables you to mark any strings used in your application as subject to localization, by wrapping them in functions such as ``gettext(str)`` and ``ngettext(singular, plural, num)``. For brevity, the -``gettext`` function is often aliased to ``_(str)``, so you can write:: +``gettext`` function is often aliased to ``_(str)``, so you can write: + +.. code-block:: python print _("Hello") -instead of just:: +instead of just: + +.. code-block:: python print "Hello" @@ -102,5 +106,7 @@ class adds a ``merge()`` method that takes another ``Translations`` instance, and merges its contents into the catalog:: +.. code-block:: python + translations = Translations.load('main') translations.merge(Translations.load('plugin1')) diff --git a/doc/display.txt b/doc/display.txt --- a/doc/display.txt +++ b/doc/display.txt @@ -29,7 +29,9 @@ ==================== You normally access such locale data through the `Locale`_ class provided -by Babel:: +by Babel: + +.. code-block:: pycon >>> from babel import Locale >>> locale = Locale('en', 'US') @@ -60,7 +62,9 @@ These display names are of course used for date formatting, but can also be used, for example, to show a list of months to the user in their preferred -language:: +language: + +.. code-block:: pycon >>> locale = Locale('es') >>> month_names = locale.months['format']['wide'].items() diff --git a/doc/formatting.txt b/doc/formatting.txt --- a/doc/formatting.txt +++ b/doc/formatting.txt @@ -16,7 +16,9 @@ When working with date and time information in Python, you commonly use the classes ``date``, ``datetime`` and/or ``time`` from the `datetime package`_. Babel provides functions for locale-specific formatting of those objects in its -``dates`` module:: +``dates`` module: + +.. code-block:: pycon >>> from datetime import date, datetime, time >>> from babel.dates import format_date, format_datetime, format_time @@ -38,7 +40,9 @@ * ``long``, and * ``full``. -For example:: +For example: + +.. code-block:: pycon >>> format_date(d, format='short', locale='en') u'4/1/07' @@ -76,7 +80,9 @@ single quotes. Text within single quotes is not interpreted in any way (except for two adjacent single quotes). -For example:: +For example: + +.. code-block:: pycon >>> d = date(2007, 4, 1) >>> format_date(d, "EEE, MMM d, ''yy", locale='en') @@ -205,7 +211,9 @@ For real time-zone support, it is strongly recommended that you use the third-party package `pytz`_, which includes the definitions of practically all of the time-zones used on the world, as well as important functions for -reliably converting from UTC to local time, and vice versa:: +reliably converting from UTC to local time, and vice versa: + +.. code-block:: pycon >>> from datetime import time >>> from pytz import timezone, utc @@ -219,7 +227,9 @@ time-zone when accepting user input and displaying date/time data, respectively. You can use Babel together with ``pytz`` to apply a time-zone to any ``datetime`` or ``time`` object for display, leaving the original information -unchanged:: +unchanged: + +.. code-block:: pycon >>> british = timezone('Europe/London') >>> format_datetime(dt, 'H:mm zzzz', tzinfo=british, locale='en_US') @@ -237,7 +247,9 @@ Parsing Dates ------------- -Babel can also parse date and time information in a locale-sensitive manner:: +Babel can also parse date and time information in a locale-sensitive manner: + +.. code-block:: pycon >>> from babel.dates import parse_date, parse_datetime, parse_time @@ -246,11 +258,15 @@ ================= Support for locale-specific formatting and parsing of numbers is provided by -the ``babel.numbers`` module:: +the ``babel.numbers`` module: + +.. code-block:: pycon >>> from babel.numbers import format_number, format_decimal, format_percent -Examples:: +Examples: + +.. code-block:: pycon >>> format_decimal(1.2345, locale='en_US') u'1.234' @@ -268,7 +284,9 @@ formatting patterns, the patterns Babel supports for number formatting are based on the `Locale Data Markup Language specification`_ (LDML). -Examples:: +Examples: + +.. code-block:: pycon >>> format_decimal(-1.2345, format='#,##0.##;-#', locale='en') u'-1.23' @@ -318,11 +336,15 @@ Parsing Numbers --------------- -Babel can also parse numeric data in a locale-sensitive manner:: +Babel can also parse numeric data in a locale-sensitive manner: + +.. code-block:: pycon >>> from babel.numbers import parse_decimal, parse_number -Examples:: +Examples: + +.. code-block:: pycon >>> parse_decimal('1,099.98', locale='en_US') 1099.98 @@ -330,5 +352,5 @@ 1099.98 >>> parse_decimal('2,109,998', locale='de') Traceback (most recent call last): - ... + ... NumberFormatError: '2,109,998' is not a valid decimal number diff --git a/doc/setup.txt b/doc/setup.txt --- a/doc/setup.txt +++ b/doc/setup.txt @@ -10,7 +10,9 @@ These commands are available by default when Babel has been properly installed, and ``setup.py`` is using ``setuptools``. For projects that use plain old -``distutils``, the commands need to be registered explicitly, for example:: +``distutils``, the commands need to be registered explicitly, for example: + +.. code-block:: python from distutils.core import setup from babel.catalog import frontend as babel diff --git a/doc/style/edgewall.css b/doc/style/edgewall.css --- a/doc/style/edgewall.css +++ b/doc/style/edgewall.css @@ -1,4 +1,5 @@ -@import(docutils.css); +@import url(docutils.css); +@import url(pygments.css); html, body { height: 100%; margin: 0; padding: 0; } html, body { background: #4b4d4d url(bkgnd_pattern.png); color: #000; } @@ -14,7 +15,6 @@ h1 { font-size: 19px; margin: 2em 0 .5em; } h2 { font-size: 16px; margin: 1.5em 0 .5em; } h3 { font-size: 14px; margin: 1.2em 0 .5em; } -h1 tt, h2 tt, h3 tt { color: #666; font-size: 100%; } hr { border: none; border-top: 1px solid #ccb; margin: 2em 0; } p { margin: 0 0 1em; } @@ -40,14 +40,15 @@ border-left: 1px solid #000; margin: 0 auto 0 40px; min-height: 100%; width: 54em; padding: 0 180px 1px 20px; } -h1.title, div.document#babel h1 { border: none; color: #666; +h1.title, div.document#genshi h1 { border: none; color: #666; font-size: x-large; margin: 0 -20px 1em; padding: 2em 20px 0; } h1.title { background: url(vertbars.png) repeat-x; } -div.document#babel h1.title { text-indent: -4000px; } -div.document#babel h1 { text-align: center; } -pre.literal-block { background: #d7d7d7; border: 1px solid #e6e6e6; color: #000; - margin: 1em 1em; padding: .25em; overflow: auto; +div.document#genshi h1.title { text-indent: -4000px; } +div.document#genshi h1 { text-align: center; } +pre.literal-block, div.highlight pre { background: #f4f4f4; + border: 1px solid #e6e6e6; color: #000; margin: 1em 1em; padding: .25em; + overflow: auto; } div.contents { font-size: 90%; position: absolute; position: fixed; @@ -62,7 +63,14 @@ color: #fff; } -p.admonition-title { font-weight: bold; margin-bottom: 0; } -div.note, div.warning { font-style: italic; margin-left: 2em; - margin-right: 2em; +div.admonition, div.attention, div.caution, div.danger, div.error, div.hint, +div.important, div.note, div.tip, div.warning { + border: none; color: #333; font-style: italic; margin: 1em 2em; } +div.attention p.admonition-title, div.caution p.admonition-title, div.danger +p.admonition-title, div.error p.admonition-title, +div.warning p.admonition-title { + color: #b00; +} +p.admonition-title { margin-bottom: 0; text-transform: uppercase; } +tt.docutils { background-color: transparent; } diff --git a/doc/style/pygments.css b/doc/style/pygments.css new file mode 100644 --- /dev/null +++ b/doc/style/pygments.css @@ -0,0 +1,57 @@ +div.highlight { background: #ffffff; } +div.highlight .c { color: #999988; font-style: italic } +div.highlight .err { color: #a61717; background-color: #e3d2d2 } +div.highlight .k { font-weight: bold } +div.highlight .o { font-weight: bold } +div.highlight .cm { color: #999988; font-style: italic } +div.highlight .cp { color: #999999; font-weight: bold } +div.highlight .c1 { color: #999988; font-style: italic } +div.highlight .cs { color: #999999; font-weight: bold; font-style: italic } +div.highlight .gd { color: #000000; background-color: #ffdddd } +div.highlight .ge { font-style: italic } +div.highlight .gr { color: #aa0000 } +div.highlight .gh { color: #999999 } +div.highlight .gi { color: #000000; background-color: #ddffdd } +div.highlight .go { color: #888888 } +div.highlight .gp { color: #555555 } +div.highlight .gs { font-weight: bold } +div.highlight .gu { color: #aaaaaa } +div.highlight .gt { color: #aa0000 } +div.highlight .kc { font-weight: bold } +div.highlight .kd { font-weight: bold } +div.highlight .kp { font-weight: bold } +div.highlight .kr { font-weight: bold } +div.highlight .kt { color: #445588; font-weight: bold } +div.highlight .m { color: #009999 } +div.highlight .s { color: #bb8844 } +div.highlight .na { color: #008080 } +div.highlight .nb { color: #999999 } +div.highlight .nc { color: #445588; font-weight: bold } +div.highlight .no { color: #008080 } +div.highlight .ni { color: #800080 } +div.highlight .ne { color: #990000; font-weight: bold } +div.highlight .nf { color: #990000; font-weight: bold } +div.highlight .nn { color: #555555 } +div.highlight .nt { color: #000080 } +div.highlight .nv { color: #008080 } +div.highlight .ow { font-weight: bold } +div.highlight .mf { color: #009999 } +div.highlight .mh { color: #009999 } +div.highlight .mi { color: #009999 } +div.highlight .mo { color: #009999 } +div.highlight .sb { color: #bb8844 } +div.highlight .sc { color: #bb8844 } +div.highlight .sd { color: #bb8844 } +div.highlight .s2 { color: #bb8844 } +div.highlight .se { color: #bb8844 } +div.highlight .sh { color: #bb8844 } +div.highlight .si { color: #bb8844 } +div.highlight .sx { color: #bb8844 } +div.highlight .sr { color: #808000 } +div.highlight .s1 { color: #bb8844 } +div.highlight .ss { color: #bb8844 } +div.highlight .bp { color: #999999 } +div.highlight .vc { color: #008080 } +div.highlight .vg { color: #008080 } +div.highlight .vi { color: #008080 } +div.highlight .il { color: #009999 } diff --git a/setup.py b/setup.py --- a/setup.py +++ b/setup.py @@ -35,9 +35,29 @@ def run(self): from docutils.core import publish_cmdline + from docutils.nodes import raw + from docutils.parsers import rst + docutils_conf = os.path.join('doc', 'docutils.conf') epydoc_conf = os.path.join('doc', 'epydoc.conf') + try: + from pygments import highlight + from pygments.lexers import get_lexer_by_name + from pygments.formatters import HtmlFormatter + + def code_block(name, arguments, options, content, lineno, + content_offset, block_text, state, state_machine): + lexer = get_lexer_by_name(arguments[0]) + html = highlight('\n'.join(content), lexer, HtmlFormatter()) + return [raw('', html, format='html')] + code_block.arguments = (1, 0, 0) + code_block.options = {'language' : rst.directives.unchanged} + code_block.content = 1 + rst.directives.register_directive('code-block', code_block) + except ImportError: + print 'Pygments not installed, syntax highlighting disabled' + for source in glob('doc/*.txt'): dest = os.path.splitext(source)[0] + '.html' if not os.path.exists(dest) or \