# HG changeset patch # User cmlenz # Date 1181126501 0 # Node ID ca7d707d51b0aa22a22c1ab7f51841c00aaf8499 # Parent 1997f7af845c2bfcb5e5146c6f0d31c8f6ccc3c7 Use syntax highlighting on all the other doc pages, too. diff --git a/doc/filters.txt b/doc/filters.txt --- a/doc/filters.txt +++ b/doc/filters.txt @@ -26,7 +26,9 @@ ``HTMLFormFiller`` takes a dictionary of data to populate the form with, where the keys should match the names of form elements, and the values determine the -values of those controls. For example:: +values of those controls. For example: + +.. code-block:: pycon >>> from genshi.filters import HTMLFormFiller >>> from genshi.template import MarkupTemplate @@ -90,7 +92,9 @@ The filter ``genshi.filters.html.HTMLSanitizer`` filter can be used to clean up user-submitted HTML markup, removing potentially dangerous constructs that could -be used for various kinds of abuse, such as cross-site scripting (XSS) attacks:: +be used for various kinds of abuse, such as cross-site scripting (XSS) attacks: + +.. code-block:: pycon >>> from genshi.filters import HTMLSanitizer >>> from genshi.input import HTML @@ -115,7 +119,9 @@ filter will still perform sanitization on the contents any encountered inline styles: the proprietary ``expression()`` function (supported only by Internet Explorer) is removed, and any property using an ``url()`` which a potentially -dangerous URL scheme (such as ``javascript:``) are also stripped out:: +dangerous URL scheme (such as ``javascript:``) are also stripped out: + +.. code-block:: pycon >>> from genshi.filters import HTMLSanitizer >>> from genshi.input import HTML @@ -142,7 +148,9 @@ The filter ``genshi.filters.transform.Transformer`` provides a convenient way to transform or otherwise work with markup event streams. It allows you to specify which parts of the stream you're interested in with XPath expressions, and then -attach a variety of transformations to the parts that match:: +attach a variety of transformations to the parts that match: + +.. code-block:: pycon >>> from genshi.builder import tag >>> from genshi.core import TEXT @@ -176,7 +184,9 @@ Please consult the API documentation a complete list. In addition, you can also perform custom transformations. For example, the -following defines a transformation that changes the name of a tag:: +following defines a transformation that changes the name of a tag: + +.. code-block:: pycon >>> from genshi import QName >>> from genshi.filters.transform import ENTER, EXIT @@ -197,7 +207,9 @@ tag name. Custom transformations can be applied using the `|` operator on the transformer -instance:: +instance: + +.. code-block:: pycon >>> xform = Transformer('body//em').apply(unicode.upper, TEXT) >>> xform |= RenameTransformation('u') @@ -209,6 +221,7 @@ +.. note:: The transformation filter was added in Genshi 0.5. Translator @@ -223,3 +236,5 @@ be used to extract localizable messages from a template. Please refer to the API documentation for more information on this filter. + +.. note:: The translation filter was added in Genshi 0.4. diff --git a/doc/streams.txt b/doc/streams.txt --- a/doc/streams.txt +++ b/doc/streams.txt @@ -24,7 +24,7 @@ For example, the functions ``XML()`` and ``HTML()`` can be used to convert literal XML or HTML text to a markup stream: -.. code-block:: python +.. code-block:: pycon >>> from genshi import XML >>> stream = XML('

Some text and ' @@ -43,7 +43,7 @@ * ``pos`` is a ``(filename, lineno, column)`` tuple that describes where the event “comes from”. -.. code-block:: python +.. code-block:: pycon >>> for kind, data, pos in stream: ... print kind, `data`, pos @@ -139,7 +139,7 @@ Here's the output from ``serialize()``: -.. code-block:: python +.. code-block:: pycon >>> for output in stream.serialize(): ... print `output` @@ -155,7 +155,7 @@ And here's the output from ``render()``: -.. code-block:: python +.. code-block:: pycon >>> print stream.render()

Some text and a link.

@@ -164,7 +164,7 @@ the events are serialzed to text. This parameter can be either “xml” (the default), “xhtml”, “html”, “text”, or a custom serializer class: -.. code-block:: python +.. code-block:: pycon >>> print stream.render('html')

Some text and a link.

@@ -178,7 +178,7 @@ The different serializer classes in ``genshi.output`` can also be used directly: -.. code-block:: python +.. code-block:: pycon >>> from genshi.filters import HTMLSanitizer >>> from genshi.output import TextSerializer @@ -187,7 +187,7 @@ The pipe operator allows a nicer syntax: -.. code-block:: python +.. code-block:: pycon >>> print stream | HTMLSanitizer() | TextSerializer() Some text and a link. @@ -228,7 +228,7 @@ XPath can be used to extract a specific subset of the stream via the ``select()`` method: -.. code-block:: python +.. code-block:: pycon >>> substream = stream.select('a') >>> substream @@ -241,7 +241,7 @@ and cannot be rendered again. To work around this, you can wrap such a stream in a ``list``: -.. code-block:: python +.. code-block:: pycon >>> from genshi import Stream >>> substream = Stream(list(stream.select('a'))) diff --git a/doc/style/edgewall.css b/doc/style/edgewall.css --- a/doc/style/edgewall.css +++ b/doc/style/edgewall.css @@ -67,5 +67,10 @@ div.important, div.note, div.tip, div.warning { border: none; color: #333; font-style: italic; margin: 1em 2em; } -p.admonition-title { margin-bottom: 0; } -div.note, div.warning { font-style: italic; } +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/templates.txt b/doc/templates.txt --- a/doc/templates.txt +++ b/doc/templates.txt @@ -32,7 +32,9 @@ used to generate any kind of HTML or XML output, as they provide many advantages over simple text-based templates (such as automatic escaping of strings). -The following illustrates a very basic Genshi markup template:: +The following illustrates a very basic Genshi markup template: + +.. code-block:: genshi @@ -79,7 +83,9 @@ A *text template* is a simple plain text document that can also contain embedded Python code. Text templates can be used to generate simple *non-markup* text -formats, such as the body of an plain text email. For example:: +formats, such as the body of an plain text email. For example: + +.. code-block:: genshitext Dear $name, @@ -103,7 +109,9 @@ be made available to the template as keyword arguments. * Serialize the resulting stream using its ``render()`` method. -For example:: +For example: + +.. code-block:: pycon >>> from genshi.template import MarkupTemplate >>> tmpl = MarkupTemplate('

Hello, $name!

') @@ -111,7 +119,9 @@ >>> print stream.render()

Hello, world!

-Using a text template is similar:: +Using a text template is similar: + +.. code-block:: pycon >>> from genshi.template import TextTemplate >>> tmpl = TextTemplate('Hello, $name!') @@ -129,7 +139,9 @@ automatically cached, and only parsed again when the template file changes. In addition, it enables the use of a *template search path*, allowing template directories to be spread across different file-system locations. Using a -template loader would generally look as follows:: +template loader would generally look as follows: + +.. code-block:: python from genshi.template import TemplateLoader loader = TemplateLoader([templates_dir1, templates_dir2]) @@ -158,7 +170,9 @@ If the expression starts with a letter and contains only letters, digits, dots, and underscores, the curly braces may be omitted. In all other cases, the braces are required so that the template processor knows where the expression -ends:: +ends: + +.. code-block:: pycon >>> from genshi.template import MarkupTemplate >>> tmpl = MarkupTemplate('${items[0].capitalize()} item') @@ -168,7 +182,9 @@ Expressions support the full power of Python. In addition, it is possible to access items in a dictionary using “dotted notation” (i.e. as if they were attributes), and vice-versa (i.e. access attributes as if they were items in a -dictionary):: +dictionary): + +.. code-block:: pycon >>> from genshi.template import MarkupTemplate >>> tmpl = MarkupTemplate('${dict.foo}') @@ -188,7 +204,9 @@ =========== XML templates also support full Python code blocks using the ```` -processing instruction:: +processing instruction: + +.. code-block:: genshi
-This will produce the following output:: +This will produce the following output: + +.. code-block:: genshi
Hello, world! @@ -229,7 +249,9 @@ ============== By default, Genshi allows you to access variables that are not defined, without -raising a ``NameError`` exception as regular Python code would:: +raising a ``NameError`` exception as regular Python code would: + +.. code-block:: pycon >>> from genshi.template import MarkupTemplate >>> tmpl = MarkupTemplate('

${doh}

') @@ -237,7 +259,9 @@

You *will* however get an exception if you try to call an undefined variable, or -do anything else with it, such as accessing its attributes:: +do anything else with it, such as accessing its attributes: + +.. code-block:: pycon >>> from genshi.template import MarkupTemplate >>> tmpl = MarkupTemplate('

${doh.oops}

') @@ -247,7 +271,9 @@ UndefinedError: "doh" not defined If you need to know whether a variable is defined, you can check its type -against the ``Undefined`` class, for example in a conditional directive:: +against the ``Undefined`` class, for example in a conditional directive: + +.. code-block:: pycon >>> from genshi.template import MarkupTemplate >>> tmpl = MarkupTemplate('

${type(doh) is not Undefined}

') @@ -266,7 +292,9 @@ This mode can be chosen by passing the ``lookup='strict'`` keyword argument to the template initializer, or by passing the ``variable_lookup='strict'`` keyword -argument to the ``TemplateLoader`` initializer:: +argument to the ``TemplateLoader`` initializer: + +.. code-block:: pycon >>> from genshi.template import MarkupTemplate >>> tmpl = MarkupTemplate('

${doh}

', lookup='strict') diff --git a/doc/text-templates.txt b/doc/text-templates.txt --- a/doc/text-templates.txt +++ b/doc/text-templates.txt @@ -57,7 +57,9 @@ ``#if`` --------- -The content is only rendered if the expression evaluates to a truth value:: +The content is only rendered if the expression evaluates to a truth value: + +.. code-block:: genshitext #if foo ${bar} @@ -82,7 +84,9 @@ no ``#when`` branch matches, the ``#otherwise`` branch is be rendered. If the ``#choose`` directive has no argument the nested ``#when`` directives -will be tested for truth:: +will be tested for truth: + +.. code-block:: genshitext The answer is: #choose @@ -103,7 +107,9 @@ 1 If the ``#choose`` does have an argument, the nested ``#when`` directives will -be tested for equality to the parent ``#choose`` value:: +be tested for equality to the parent ``#choose`` value: + +.. code-block:: genshitext The answer is: #choose 1 @@ -132,7 +138,9 @@ ``#for`` ---------- -The content is repeated for every item in an iterable:: +The content is repeated for every item in an iterable: + +.. code-block:: genshitext Your items: #for item in items @@ -158,7 +166,9 @@ The ``#def`` directive can be used to create macros, i.e. snippets of template text that have a name and optionally some parameters, and that can be inserted -in other places:: +in other places: + +.. code-block:: genshitext #def greeting(name) Hello, ${name}! @@ -172,7 +182,9 @@ Hello, everyone else! If a macro doesn't require parameters, it can be defined as well as called -without the parenthesis. For example:: +without the parenthesis. For example: + +.. code-block:: genshitext #def greeting Hello, world! @@ -191,7 +203,9 @@ ------------ To reuse common parts of template text across template files, you can include -other files using the ``#include`` directive:: +other files using the ``#include`` directive: + +.. code-block:: genshitext #include "base.txt" @@ -208,7 +222,9 @@ Just like other directives, the argument to the ``#include`` directive accepts any Python expression, so the path to the included template can be determined -dynamically:: +dynamically: + +.. code-block:: genshitext #include '%s.txt' % filename @@ -232,7 +248,9 @@ than once, and that actually results in a database query, assigning the results to a variable using this directive would probably help. -For example:: +For example: + +.. code-block:: genshitext Magic numbers! #with y=7; z=x+10 diff --git a/doc/xml-templates.txt b/doc/xml-templates.txt --- a/doc/xml-templates.txt +++ b/doc/xml-templates.txt @@ -42,7 +42,9 @@ conditionals and looping, among others. To use directives in a template, the namespace must be declared, which is -usually done on the root element:: +usually done on the root element: + +.. code-block:: genshi -This is basically equivalent to the following:: +This is basically equivalent to the following: + +.. code-block:: genshi ${bar}
Given the data ``foo=True`` and ``bar='Hello'`` in the template context, this -would produce:: +would produce: + +.. code-block:: html
Hello
-This directive can also be used as an element:: +This directive can also be used as an element: + +.. code-block:: genshi
@@ -129,7 +141,9 @@ if no ``py:when`` branch matches, the ``py:otherwise`` branch is rendered. If the ``py:choose`` directive is empty the nested ``py:when`` directives will -be tested for truth:: +be tested for truth: + +.. code-block:: genshi
0 @@ -137,14 +151,18 @@ 2
-This would produce the following output:: +This would produce the following output: + +.. code-block:: html
1
If the ``py:choose`` directive contains an expression the nested ``py:when`` -directives will be tested for equality to the parent ``py:choose`` value:: +directives will be tested for equality to the parent ``py:choose`` value: + +.. code-block:: genshi
0 @@ -152,7 +170,9 @@ 2
-This would produce the following output:: +This would produce the following output: + +.. code-block:: html
1 @@ -167,19 +187,25 @@ ``py:for`` ---------- -The element is repeated for every item in an iterable:: +The element is repeated for every item in an iterable: + +.. code-block:: genshi
  • ${item}
-Given ``items=[1, 2, 3]`` in the context data, this would produce:: +Given ``items=[1, 2, 3]`` in the context data, this would produce: + +.. code-block:: html
  • 1
  • 2
  • 3
-This directive can also be used as an element:: +This directive can also be used as an element: + +.. code-block:: genshi
    @@ -199,7 +225,9 @@ The ``py:def`` directive can be used to create macros, i.e. snippets of template code that have a name and optionally some parameters, and that can be -inserted in other places:: +inserted in other places: + +.. code-block:: genshi

    @@ -209,7 +237,9 @@ ${greeting('everyone else')}

    -The above would be rendered to:: +The above would be rendered to: + +.. code-block:: html

    @@ -221,7 +251,9 @@

    If a macro doesn't require parameters, it can be defined without the -parenthesis. For example:: +parenthesis. For example: + +.. code-block:: genshi

    @@ -230,7 +262,9 @@ ${greeting()}

    -The above would be rendered to:: +The above would be rendered to: + +.. code-block:: html

    @@ -238,7 +272,9 @@

    -This directive can also be used as an element:: +This directive can also be used as an element: + +.. code-block:: genshi
    @@ -258,7 +294,9 @@ content. For example, the match template defined in the following template matches any -element with the tag name “greeting”:: +element with the tag name “greeting”: + +.. code-block:: genshi
    @@ -267,7 +305,9 @@
    -This would result in the following output:: +This would result in the following output: + +.. code-block:: html
    @@ -282,7 +322,9 @@ .. _`Using XPath`: streams.html#using-xpath -This directive can also be used as an element:: +This directive can also be used as an element: + +.. code-block:: genshi
    @@ -306,19 +348,25 @@ than once, and that actually results in a database query, assigning the results to a variable using this directive would probably help. -For example:: +For example: + +.. code-block:: genshi
    $x $y $z
    -Given ``x=42`` in the context data, this would produce:: +Given ``x=42`` in the context data, this would produce: + +.. code-block:: html
    42 7 52
    -This directive can also be used as an element:: +This directive can also be used as an element: + +.. code-block:: genshi
    $x $y $z @@ -338,21 +386,27 @@ ``py:attrs`` ------------ -This directive adds, modifies or removes attributes from the element:: +This directive adds, modifies or removes attributes from the element: + +.. code-block:: genshi
    • Bar
    Given ``foo={'class': 'collapse'}`` in the template context, this would -produce:: +produce: + +.. code-block:: html
    • Bar
    Attributes with the value ``None`` are omitted, so given ``foo={'class': None}`` -in the context for the same template this would produce:: +in the context for the same template this would produce: + +.. code-block:: html
    • Bar
    • @@ -367,13 +421,17 @@ -------------- This directive replaces any nested content with the result of evaluating the -expression:: +expression: + +.. code-block:: genshi
      • Hello
      -Given ``bar='Bye'`` in the context data, this would produce:: +Given ``bar='Bye'`` in the context data, this would produce: + +.. code-block:: html
      • Bye
      • @@ -388,13 +446,17 @@ -------------- This directive replaces the element itself with the result of evaluating the -expression:: +expression: + +.. code-block:: genshi
        Hello
        -Given ``bar='Bye'`` in the context data, this would produce:: +Given ``bar='Bye'`` in the context data, this would produce: + +.. code-block:: html
        Bye @@ -410,13 +472,17 @@ This directive conditionally strips the top-level element from the output. When the value of the ``py:strip`` attribute evaluates to ``True``, the element is -stripped from the output:: +stripped from the output: + +.. code-block:: genshi
        foo
        -This would be rendered as:: +This would be rendered as: + +.. code-block:: html
        foo @@ -462,7 +528,9 @@ For this, you need to declare the XInclude namespace (commonly bound to the prefix “xi”) and use the ```` element where you want the external -file to be pulled in:: +file to be pulled in: + +.. code-block:: genshi @@ -497,7 +567,9 @@ Incudes in Genshi are fully dynamic: Just like normal attributes, the `href` attribute accepts expressions, and directives_ can be used on the ```` element just as on any other element, meaning you can do -things like conditional includes:: +things like conditional includes: + +.. code-block:: genshi @@ -509,17 +581,23 @@ Comments -------- -Normal XML/HTML comment syntax can be used in templates:: +Normal XML/HTML comment syntax can be used in templates: + +.. code-block:: genshi However, such comments get passed through the processing pipeline and are by default included in the final output. If that's not desired, prefix the comment -text with an exclamation mark:: +text with an exclamation mark: + +.. code-block:: genshi Note that it does not matter whether there's whitespace before or after the -exclamation mark, so the above could also be written as follows:: +exclamation mark, so the above could also be written as follows: + +.. code-block:: genshi diff --git a/doc/xpath.txt b/doc/xpath.txt --- a/doc/xpath.txt +++ b/doc/xpath.txt @@ -62,24 +62,25 @@ Querying Streams ---------------- -:: - - from genshi.input import XML +The ``Stream`` class provides a ``select(path)`` function that can be used to +retrieve subsets of the stream: - doc = XML(''' - - - Foo - - - Bar - - - ''') - print doc.select('items/item[@status="closed"]/summary/text()') +.. code-block:: pycon -This would result in the following output:: - + >>> from genshi.input import XML + + >>> doc = XML(''' + ... + ... + ... Foo + ... + ... + ... Bar + ... + ... + ... ''') + + >>> print doc.select('items/item[@status="closed"]/summary/text()') Bar