comparison doc/filters.txt @ 902:09cc3627654c experimental-inline

Sync `experimental/inline` branch with [source:trunk@1126].
author cmlenz
date Fri, 23 Apr 2010 21:08:26 +0000
parents 1837f39efd6f
children
comparison
equal deleted inserted replaced
830:de82830f8816 902:09cc3627654c
45 ... <input type="checkbox" name="remember" /> Remember me 45 ... <input type="checkbox" name="remember" /> Remember me
46 ... </label> 46 ... </label>
47 ... </p> 47 ... </p>
48 ... </form>""") 48 ... </form>""")
49 >>> filler = HTMLFormFiller(data=dict(username='john', remember=True)) 49 >>> filler = HTMLFormFiller(data=dict(username='john', remember=True))
50 >>> print template.generate() | filler 50 >>> print(template.generate() | filler)
51 <form> 51 <form>
52 <p> 52 <p>
53 <label>User name: 53 <label>User name:
54 <input type="text" name="username" value="john"/> 54 <input type="text" name="username" value="john"/>
55 </label><br/> 55 </label><br/>
102 >>> html = HTML("""<div> 102 >>> html = HTML("""<div>
103 ... <p>Innocent looking text.</p> 103 ... <p>Innocent looking text.</p>
104 ... <script>alert("Danger: " + document.cookie)</script> 104 ... <script>alert("Danger: " + document.cookie)</script>
105 ... </div>""") 105 ... </div>""")
106 >>> sanitize = HTMLSanitizer() 106 >>> sanitize = HTMLSanitizer()
107 >>> print html | sanitize 107 >>> print(html | sanitize)
108 <div> 108 <div>
109 <p>Innocent looking text.</p> 109 <p>Innocent looking text.</p>
110 </div> 110 </div>
111 111
112 In this example, the ``<script>`` tag was removed from the output. 112 In this example, the ``<script>`` tag was removed from the output.
128 128
129 >>> html = HTML("""<div> 129 >>> html = HTML("""<div>
130 ... <br style="background: url(javascript:alert(document.cookie); color: #000" /> 130 ... <br style="background: url(javascript:alert(document.cookie); color: #000" />
131 ... </div>""") 131 ... </div>""")
132 >>> sanitize = HTMLSanitizer(safe_attrs=HTMLSanitizer.SAFE_ATTRS | set(['style'])) 132 >>> sanitize = HTMLSanitizer(safe_attrs=HTMLSanitizer.SAFE_ATTRS | set(['style']))
133 >>> print html | sanitize 133 >>> print(html | sanitize)
134 <div> 134 <div>
135 <br style="color: #000"/> 135 <br style="color: #000"/>
136 </div> 136 </div>
137 137
138 .. warning:: You should probably not rely on the ``style`` filtering, as 138 .. warning:: You should probably not rely on the ``style`` filtering, as
162 ... <body> 162 ... <body>
163 ... Some <em>body</em> text. 163 ... Some <em>body</em> text.
164 ... </body> 164 ... </body>
165 ... </html>''') 165 ... </html>''')
166 166
167 >>> print html | Transformer('body/em').map(unicode.upper, TEXT) \ 167 >>> print(html | Transformer('body/em').map(unicode.upper, TEXT)
168 ... .unwrap().wrap(tag.u).end() \ 168 ... .unwrap().wrap(tag.u).end()
169 ... .select('body/u') \ 169 ... .select('body/u')
170 ... .prepend('underlined ') 170 ... .prepend('underlined '))
171 <html> 171 <html>
172 <head><title>Some Title</title></head> 172 <head><title>Some Title</title></head>
173 <body> 173 <body>
174 Some <u>underlined BODY</u> text. 174 Some <u>underlined BODY</u> text.
175 </body> 175 </body>
214 214
215 .. code-block:: pycon 215 .. code-block:: pycon
216 216
217 >>> xform = Transformer('body//em').map(unicode.upper, TEXT) \ 217 >>> xform = Transformer('body//em').map(unicode.upper, TEXT) \
218 >>> xform = xform.apply(RenameTransformation('u')) 218 >>> xform = xform.apply(RenameTransformation('u'))
219 >>> print html | xform 219 >>> print(html | xform)
220 <html> 220 <html>
221 <head><title>Some Title</title></head> 221 <head><title>Some Title</title></head>
222 <body> 222 <body>
223 Some <u>BODY</u> text. 223 Some <u>BODY</u> text.
224 </body> 224 </body>
Copyright (C) 2012-2017 Edgewall Software