Mercurial > genshi > mirror
changeset 812:967236817c6a stable-0.5.x
Ported [1013] to 0.5.x branch.
author | cmlenz |
---|---|
date | Mon, 09 Mar 2009 09:00:00 +0000 |
parents | eebb2c723f23 |
children | 62b7d1a058dd |
files | doc/templates.txt |
diffstat | 1 files changed, 38 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- a/doc/templates.txt +++ b/doc/templates.txt @@ -203,6 +203,44 @@ See `Error Handling`_ below for details on how such errors are handled. +Escaping +======== + +If you need to include a literal dollar sign in the output where Genshi would +normally detect an expression, you can simply add another dollar sign: + +.. code-block:: pycon + + >>> from genshi.template import MarkupTemplate + >>> tmpl = MarkupTemplate('<em>$foo</em>') # Wanted "$foo" as literal output + >>> print tmpl.generate() + Traceback (most recent call last): + ... + UndefinedError: "foo" not defined + >>> tmpl = MarkupTemplate('<em>$$foo</em>') + >>> print tmpl.generate() + <em>$foo</em> + +But note that this is not necessary if the characters following the dollar sign +do not qualify as an expression. For example, the following needs no escaping: + +.. code-block:: pycon + + >>> tmpl = MarkupTemplate('<script>$(function() {})</script>') + >>> print tmpl.generate() + <script>$(function() {})</script> + +On the other hand, Genshi will always replace two dollar signs in text with a +single dollar sign, so you'll need to use three dollar signs to get two in the +output: + +.. code-block:: pycon + + >>> tmpl = MarkupTemplate('<script>$$$("div")</script>') + >>> print tmpl.generate() + <script>$$("div")</script> + + .. _`code blocks`: Code Blocks