diff --git a/django/template/defaulttags.py b/django/template/defaulttags.py
index ea1dd02..1548ab1 100644
a
|
b
|
class WithNode(Node):
|
480 | 480 | context.pop() |
481 | 481 | return output |
482 | 482 | |
| 483 | |
| 484 | class DoctypeNode(Node): |
| 485 | def __init__(self, type): |
| 486 | self.type = type |
| 487 | self.doctypes = { |
| 488 | 'html4strict': '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">', |
| 489 | 'html4trans': '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">', |
| 490 | 'html4frameset': '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Frameset//EN" "http://www.w3.org/TR/html4/frameset.dtd">', |
| 491 | 'xhtml1strict': '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">', |
| 492 | 'xhtml1trans': '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">', |
| 493 | 'xhtml1frameset': 'o<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Frameset//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-frameset.dtd">', |
| 494 | 'html5': '<!DOCTYPE HTML>' |
| 495 | } |
| 496 | |
| 497 | def render(self, context): |
| 498 | if self.type in self.doctypes: |
| 499 | context['_doctype'] = self.type # Set context variable for possible use by other HTML output mechanisms. |
| 500 | return self.doctypes[self.type] |
| 501 | else: |
| 502 | return '' |
| 503 | |
| 504 | |
483 | 505 | @register.tag |
484 | 506 | def autoescape(parser, token): |
485 | 507 | """ |
… |
… |
def do_with(parser, token):
|
1358 | 1380 | nodelist = parser.parse(('endwith',)) |
1359 | 1381 | parser.delete_first_token() |
1360 | 1382 | return WithNode(None, None, nodelist, extra_context=extra_context) |
| 1383 | |
| 1384 | |
| 1385 | @register.tag |
| 1386 | def doctype(parser, token): |
| 1387 | """ |
| 1388 | Creates the HTML DOCTYPE declaration based on given type. |
| 1389 | |
| 1390 | Usage format:: |
| 1391 | |
| 1392 | {% doctype type %} |
| 1393 | |
| 1394 | ``type`` is one of: html4strict, html4trans, html4frameset, xhtml1strict, xhtml1trans, xhtml1frameset, html5. |
| 1395 | |
| 1396 | Examples: |
| 1397 | * ``{% doctype html4strict %}`` will output the HTML 4.01 Strict doctype. |
| 1398 | * ``{% doctype xhtml1trans %}`` will output the XHTML 1.0 Transitional doctype. |
| 1399 | """ |
| 1400 | bits = list(token.split_contents()) |
| 1401 | tagname, bits = bits[0], bits[1:] |
| 1402 | type = '' |
| 1403 | # Type bit |
| 1404 | if len(bits): |
| 1405 | type = bits.pop() |
| 1406 | else: |
| 1407 | raise TemplateSyntaxError("No type given for %r tag" % tagname) |
| 1408 | if len(bits) > 0: |
| 1409 | raise TemplateSyntaxError("Incorrect format for %r tag" % tagname) |
| 1410 | return DoctypeNode(type) |
diff --git a/docs/ref/templates/builtins.txt b/docs/ref/templates/builtins.txt
index 07ac284..ca4003f 100644
a
|
b
|
debug
|
191 | 191 | Outputs a whole load of debugging information, including the current context |
192 | 192 | and imported modules. |
193 | 193 | |
| 194 | .. templatetag:: doctype |
| 195 | |
| 196 | doctype |
| 197 | ^^^^^^^ |
| 198 | |
| 199 | .. versionadded:: 1.5 |
| 200 | |
| 201 | Creates the HTML DOCTYPE declaration based on given type. |
| 202 | |
| 203 | Usage format:: |
| 204 | |
| 205 | {% doctype type %} |
| 206 | |
| 207 | ``type`` is one of: html4strict, html4trans, html4frameset, xhtml1strict, xhtml1trans, xhtml1frameset, html5. |
| 208 | |
| 209 | Examples: |
| 210 | |
| 211 | * ``{% doctype html4strict %}`` will output the HTML 4.01 Strict doctype. |
| 212 | * ``{% doctype xhtml1trans %}`` will output the XHTML 1.0 Transitional doctype. |
| 213 | |
194 | 214 | .. templatetag:: extends |
195 | 215 | |
196 | 216 | extends |
diff --git a/tests/regressiontests/templates/tests.py b/tests/regressiontests/templates/tests.py
index a150d1c..ab9c844 100644
a
|
b
|
class Templates(unittest.TestCase):
|
1640 | 1640 | 'verbatim-tag04': ('{% verbatim %}{% verbatim %}{% endverbatim %}{% endverbatim %}', {}, template.TemplateSyntaxError), |
1641 | 1641 | 'verbatim-tag05': ('{% verbatim %}{% endverbatim %}{% verbatim %}{% endverbatim %}', {}, ''), |
1642 | 1642 | 'verbatim-tag06': ("{% verbatim special %}Don't {% endverbatim %} just yet{% endverbatim special %}", {}, "Don't {% endverbatim %} just yet"), |
| 1643 | |
| 1644 | |
| 1645 | # Doctype template tag outputs |
| 1646 | 'doctype-taghtml4strict': ('{% doctype html4strict %}', {}, '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">'), |
| 1647 | 'doctype-taghtml4trans': ('{% doctype html4trans %}', {}, '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">'), |
| 1648 | 'doctype-taghtml4frameset': ('{% doctype html4frameset %}', {}, '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Frameset//EN" "http://www.w3.org/TR/html4/frameset.dtd">'), |
| 1649 | 'doctype-tagxhtml1strict': ('{% doctype xhtml1strict %}', {}, '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">'), |
| 1650 | 'doctype-tagxhtml1trans': ('{% doctype xhtml1trans %}', {}, '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">'), |
| 1651 | 'doctype-tagxhtml1frameset': ('{% doctype xhtml1frameset %}', {}, '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Frameset//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-frameset.dtd">'), |
| 1652 | 'doctype-taghtml5': ('{% doctype html5 %}', {}, '<!DOCTYPE HTML>') |
1643 | 1653 | } |
1644 | 1654 | return tests |
1645 | 1655 | |