Applied leafstorm's html5faq patch
Before adoption: this commit came in with the history the project adopted, so no landing records it.
authored by Armin Ronacher · committed by Armin Ronacher · parent 235d693 · Browse files · 2 files·+115 added−71 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
2 files+115 added−71 removed
- other:+115 added−71 removed
Provenance
- Commit
5a5a4a8- Tree
3e43530- Author
Armin Ronacher <armin.ronacher@active-4.com>- Committer
Armin Ronacher <armin.ronacher@active-4.com>- Parent
235d693
2 files changed+115 added−71 removed
modified:docs/htmlfaq.rst+114 added-71 removed
1 HTML/XHTML FAQ2 ==============3 4 The Flask documentation and example applications are using HTML5. You5-will notice that in many situations when end tags are optional they are6-not used to keep the HTML cleaner and also faster to load. Because there7-is a lot of confusion about HTML and XHTML out there this document tries8-to answer some of them.5+may notice that in many situations, when end tags are optional they are6+not used, so that the HTML is cleaner and faster to load. Because there7+is much confusion about HTML and XHTML among developers, this document tries8+to answer some of the major questions.9 10 11-History on XHTML11+History of XHTML12 ----------------13 14-For a while it looked like HTML was about to be replaced by XHTML.15-However barely any websites on the internet are actually real XHTML (which16-means XHTML processed with XML rules). There are a couple of reasons why17-this is the case. It mostly has to do with Internet Explorer which does18-not accept the XHTML mimetype to switch the browser into XML mode.19-However this is really easy to bypass but barely anyone does that. This20-probably has to do with the fact that XHTML is really painful.14+For a while, it appeared that HTML was about to be replaced by XHTML.15+However, barely any websites on the Internet are actual XHTML (which is16+HTML processed using XML rules). There are a couple of major reasons17+why this is the case. One of them is Internet Explorer's lack of proper18+XHTML support. The XHTML spec states that XHTML must be served with the MIME19+type `application/xhtml+xml`, but Internet Explorer refuses to read files20+with that MIME type.21+While it is relatively easy to configure Web servers to serve XHTML properly,22+few people do. This is likely because properly using XHTML can be quite23+painful.24 22-Why is it painful? XML has very strict errorhandling. On a parsing error23-the browser is supposed to show the user an ugly error message. Most of25+One of the most important causes of pain is XML's draconian (strict and26+ruthless) error handling. When an XML parsing error is encountered,27+the browser is supposed to show the user an ugly error message, instead28+of attempting to recover from the error and display what it can. Most of29 the (X)HTML generation on the web is based on non-XML template engines30 (such as Jinja, the one used in Flask) which do not protect you from26-accidentally creating invalid HTML. There are XML based template engines27-but they usually come with a larger runtime overhead and are not as28-straightforward to use because they have to obey XML rules.31+accidentally creating invalid XHTML. There are XML based template engines,32+such as Kid and the popular Genshi, but they often come with a larger33+runtime overhead and, are not as straightforward to use because they have34+to obey XML rules.35 30-Now the majority of users assumed they were using XHTML though. The31-reasons for that is that they sticked an XHTML doctype on top of the32-document and self-closed all necessary tags (``<br>`` becomes ``<br/>`` or33-``<br></br>`` in XHTML). However even if the document properly validates34-as XHTML there are still other things to keep in mind.36+The majority of users, however, assumed they were properly using XHTML.37+They wrote an XHTML doctype at the top of the document and self-closed all38+the necessary tags (``<br>`` becomes ``<br/>`` or ``<br></br>`` in XHTML).39+However, even if the document properly validates as XHTML, what really40+determines XHTML/HTML processing in browsers is the MIME type, which as41+said before is often not set properly. So the valid XHTML was being treated42+as invalid HTML.43 36-XHTML also changes the way you work with JavaScript because you now have37-to use the namespaced DOM interface with the XHTML namespace to query for38-HTML elements.44+XHTML also changed the way JavaScript is used. To properly work with XHTML,45+programmers have to use the namespaced DOM interface with the XHTML46+namespace to query for HTML elements.47 48 History of HTML549 ----------------50 43-HTML5 was started in 2004 under the name Web Applications 1.0 by the44-WHATWG (Apple, Mozilla, Opera) and the idea was to write a new and45-improved specification of HTML based on actual browser behaviour instead46-of behaviour that exists on the paper but could not be implemented47-because of backwards compatibility with the already existing web.51+Development of the HTML5 specification was started in 2004 under the name52+"Web Applications 1.0" by the Web Hypertext Application Technology Working53+Group, or WHATWG (which was formed by the major browser vendors Apple,54+Mozilla, and Opera) with the goal of writing a new and improved HTML55+specification, based on existing browser behaviour instead of unrealistic56+and backwards-incompatible specifications.57 49-For example in theory HTML4 ``<title/Hello/`` means exactly the same as50-``<title>Hello</title>`` but because existing websites are using51-pseudo-XHTML which uses the Slash in different ways, this could not be52-implemented properly.58+For example, in HTML4 ``<title/Hello/`` theoretically parses exactly the59+same as ``<title>Hello</title>``. However, since people were using60+XHTML-like tags along the lines of ``<link />``, browser vendors implemented61+the XHTML syntax over the syntax defined by the specification.62 54-In 2007 the specification was adopted as the basis of a new HTML55-specification under the umbrella of the W3C. Currently it looks like56-XHTML is losing traction, the XHTML 2 working group was disbanded and57-HTML5 is being implemented by all major browser vendors.63+In 2007, the specification was adopted as the basis of a new HTML64+specification under the umbrella of the W3C, known as HTML5. Currently,65+it appears that XHTML is losing traction, as the XHTML 2 working group has66+een disbanded and HTML5 is being implemented by all major browser vendors.67 68 HTML versus XHTML69 -----------------70 71 The following table gives you a quick overview of features available in63-HTML 4.01, XHTML 1.1 and HTML5 (we are not looking at XHTML 1.0 here which64-was superceeded by XHTML 1.1 or XHTML5 which is barely supported currently):72+HTML 4.01, XHTML 1.1 and HTML5. (XHTML 1.0 is not included, as it was73+superseded by XHTML 1.1 and the barely-used XHTML5.)74 75 .. tabularcolumns:: |p{9cm}|p{2cm}|p{2cm}|p{2cm}|76 77 +-----------------------------------------+----------+----------+----------+4 unmodified lines82 | ``<br/>`` supported | |N| | |Y| | |Y| [2]_ |83 +-----------------------------------------+----------+----------+----------+84 | ``<script/>`` supported | |N| | |Y| | |N| |85 +-----------------------------------------+----------+----------+----------+77-| might be served as `text/html` | |Y| | |N| [3]_ | |Y| |86+| should be served as `text/html` | |Y| | |N| [3]_ | |Y| |87 +-----------------------------------------+----------+----------+----------+79-| might be served as | |N| | |Y| | |N| |80-| `application/xml+html` | | | |88+| should be served as | |N| | |Y| | |N| |89+| `application/xhtml+xml` | | | |90 +-----------------------------------------+----------+----------+----------+91 | strict error handling | |N| | |Y| | |N| |92 +-----------------------------------------+----------+----------+----------+93 | inline SVG | |N| | |Y| | |Y| |3 unmodified lines97 | ``<video>`` tag | |N| | |N| | |Y| |98 +-----------------------------------------+----------+----------+----------+99 | ``<audio>`` tag | |N| | |N| | |Y| |100 +-----------------------------------------+----------+----------+----------+92-| New semantical tags like ``<article>`` | |N| | |N| | |Y| |101+| New semantic tags like ``<article>`` | |N| | |N| | |Y| |102 +-----------------------------------------+----------+----------+----------+103 95-.. [1] Obscure feature inherited from SGML not supported by browsers96-.. [2] For compatibility with XHTML generating server code for some97- tags such as ``<br>``. Should not be used.104+.. [1] This is an obscure feature inherited from SGML. It is usually not105+ supported by browsers, for reasons detailed above.106+.. [2] This is for compatibility with server code that generates XHTML for107+ tags such as ``<br>``. It should not be used in new code.108 .. [3] XHTML 1.0 is the last XHTML standard that allows to be served109 as `text/html` for backwards compatibility reasons.110 111 .. |Y| image:: _static/yes.png112 :alt: Yes113 .. |N| image:: _static/no.png114 :alt: No115 106-What does Strict Mean?107-----------------------116+What does "strict" mean?117+------------------------118 109-HTML5 has strictly defined parsing rules, but it also specifies how a110-browser should react to parsing errors. Some things people stumble upon111-with HTML5 and older HTML standards is that browsers will accept some112-things that still create the expected output even though it looks wrong113-(eg: certain tags are missing or are not closed).119+HTML5 has strictly defined parsing rules, but it also specifies exactly120+how a browser should react to parsing errors - unlike XHTML, which simply121+states parsing should abort. Some people are confused by apparently122+invalid syntax that still generates the expected results (for example,123+missing end tags or unquoted attribute values).124 115-Some of that is caused by the error handling browsers use if they116-encounter a markup error, others are actually specified. The following117-things are optional in HTML5 by standard and have to be supported by118-browsers (and are supported):125+Some of these work because of the lenient error handling most browsers use126+when they encounter a markup error, others are actually specified. The127+following constructs are optional in HTML5 by standard, but have to be128+supported by browsers:129 120-- ``<html>``, ``<head>`` or ``<body>``121-- The closing tags for ``<p>``, ``<li>``, ``<dl>``, ``<dd>``, ``<tr>``,122- ``<td>``, ``<th>``, ``<tbody>``, ``<thead>``, ``<tfoot>``.123-- quotes for attribtues if they contain no whitespace and some124- special chars that require quoting.130+- Wrapping the document in an ``<html>`` tag131+- Wrapping header elements in ``<head>`` or the body elements in132+ ``<body>``133+- Closing the ``<p>``, ``<li>``, ``<dl>``, ``<dd>``, ``<tr>``,134+ ``<td>``, ``<th>``, ``<tbody>``, ``<thead>``, or ``<tfoot>`` tags.135+- Quoting attributes, so long as they contain no whitespace or136+ special characters (like ``<``, ``>``, ``'``, or ``"``).137+- Requiring boolean attributes to have a value.138 126-This means the following piece of HTML5 is perfectly valid:139+This means the following page in HTML5 is perfectly valid:140 141 .. sourcecode:: html142 143 <!doctype html>20 unmodified lines164 </dl>165 </div>166 167 168+New technologies in HTML5169+-------------------------170+171+HTML5 adds many new features that make Web applications easier to write172+and to use.173+174+- The ``<audio>`` and ``<video>`` tags provide a way to embed audio and175+ video without complicated add-ons like QuickTime and Flask.176+- Semantic elements like ``<article>``, ``<header>``, ``<nav>``, and177+ ``<time>`` that make content easier to understand.178+- The ``<canvas>`` tag, which supports a powerful drawing API, reducing179+ the need for server-generated images to present data graphically.180+- New form control types like ``<input type="date">`` that allow user181+ agents to make entering and validating values easier.182+- Advanced JavaScript APIs like Web Storage, Web Workers, Web Sockets,183+ geolocation, and offline applications.184+185+Many other features have been added, as well. A good guide to new features186+in HTML5 is Mark Pilgrim's soon-to-be-published book, `Dive Into HTML5`_.187+Not all of them are supported in browsers yet, however, so use caution.188+189+_Dive into HTML5: http://www.diveintohtml5.org/190+191 What should be used?192 --------------------193 158-Currently the answer is HTML5. There are very few reasons to use XHTML159-with the latest development. There are some companies successfully using160-actual XML and XSLT on the client side with fallbacks to server side HTML4161-generation for browsers not supporting XML and XSLT but but it's not very162-common. Now that MathML and SVG landed in HTML5 and with the sad support163-for XHTML in Internet Explorer and many JavaScript libraries for most164-applications no reasons remain to use XHTML.194+Currently, the answer is HTML5. There are very few reasons to use XHTML195+considering the latest developments in Web browsers. To summarize the196+reasons given above:197+198+- Internet Explorer (which, sadly, currently leads in market share)199+ has poor support for XHTML.200+- Many JavaScript libraries also do not support XHTML, due to the more201+ complicated namespacing API it requires.202+- HTML5 adds several new features, including semantic tags and the203+ long-awaited ``<audio>`` and ``<video>`` tags.204+- It has the support of most browser vendors behind it.205+- It is much easier to write, and more compact.206+207+For most applications, it is undoubtably better to use HTML5 than XHTML.modified:AUTHORS+1 added
14 unmodified lines15 - Georg Brandl16 - Justin Quick17 - Kenneth Reitz18 - Marian Sigler19+- Matthew Frazier20 - Ron DuPlain21 - Sebastien Estienne22 - Simon Sapin23 - Stephane Wirtel1 unmodified line