| 481 | |
| 482 | |
| 483 | class HTMLTemplate(Template): |
| 484 | |
| 485 | default_namespace = Template.default_namespace.copy() |
| 486 | default_namespace.update(dict( |
| 487 | html=html, |
| 488 | attr=attr, |
| 489 | url=url, |
| 490 | html_quote=html_quote)) |
| 491 | |
| 492 | def _repr(self, value, pos): |
| 493 | if hasattr(value, '__html__'): |
| 494 | value = value.__html__() |
| 495 | quote = False |
| 496 | else: |
| 497 | quote = True |
| 498 | plain = Template._repr(self, value, pos) |
| 499 | if quote: |
| 500 | return html_quote(plain) |
| 501 | else: |
| 502 | return plain |
| 503 | |
| 504 | |
| 505 | def sub_html(content, **kw): |