Mercurial > genshi > mirror
changeset 811:c42693ee739d trunk
Add doc section on expression escaping. Closes #282.
author | cmlenz |
---|---|
date | Mon, 09 Mar 2009 08:57:43 +0000 |
parents | 68f652fa9e6c |
children | ae8727f7e1e1 |
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