Debian Codegraph @

docs/user/html.rst

raw
1 .. include:: ../header.rst
2
3 =====================
4 Docutils HTML writers
5 =====================
6
7 .. contents::
8
9 This document describes the HTML writers provided by Docutils.
10
11 The default `length unit`_ in HTML is "px" (pixels, 1 px = 1/96 in).
12
13 .. _length unit: ../ref/rst/restructuredtext.html#length-units
14
15 html
16 ----
17
18 :front-end: rst2html_
19
20 The writer name `html` is an alias for the default Docutils HTML writer.
21
22 The default may change with the development of HTML, browsers, Docutils,
23 and the web.
24 Currently, `html` is mapped to html4css1_, it will become an alias for
25 html5_ in Docutils 2.0.
26
27 * Use ``get_writer_by_name('html')`` or the rst2html_ front end, if you
28 want the output to be up-to-date automatically.
29
30 * Use a specific writer name or front end, if you depend on stability of the
31 generated HTML code, e.g. because you use a custom style sheet or
32 post-processing that may break otherwise.
33
34
35 html5
36 -----
37
38 :aliases: _`html5_polyglot`, xhtml
39 :front-end: rst2html5_
40 :config: `[html5 writer]`_
41
42 The *html5* writer generates valid XML that conforms to the
43 `HTML standard`_ (`polyglot HTML`_). [#safetext]_
44 New features and elements are used if they are widely supported.
45 See the `HTML5 test page`_ (and the sources `html5-features.rst`_ and
46 `html5-text-level-tags.rst`_) for differences to the html4css1_ writer.
47
48 There is no hard-coded formatting information in the HTML document.
49 Correct rendering of elements not directly supported by HTML depends on a
50 CSS_ style sheet. The provided style sheet minimal.css_ defines required
51 styling rules; plain.css_ and responsive.css_ add optional rules for
52 better legibility. Adaption of the layout is possible with `custom style
53 sheets`_. [#safetext]_
54
55 Image_ size values with unit are converted to "style" rules,
56 values without unit are rounded to the nearest integer and
57 written as "width" and "height" attributes instead.
58 This allows the specification of the image's aspect ratio
59 (to `prevent jank when loading images`__) without overwriting
60 size declarations in a CSS stylesheet.
61
62 .. [#safetext] The validity of raw HTML and custom stylesheets must be
63 ensured by the author.
64
65 .. _HTML5 test page: https://docutils.sourceforge.io/test/functional/
66 expected/standalone_rst_html5.html#differences-to-the-html4css1-writer
67 .. _html5-features.rst: https://docutils.sourceforge.io/test/functional/
68 input/data/html5-features.rst
69 .. _html5-text-level-tags.rst: https://docutils.sourceforge.io/test/functional/
70 input/data/html5-text-level-tags.rst
71 .. _rst2html5: tools.html#rst2html5
72 .. _[html5 writer]: config.html#html5-writer
73 .. _minimal.css: ../../docutils/writers/html5_polyglot/minimal.css
74 .. _plain.css: ../../docutils/writers/html5_polyglot/plain.css
75 .. _responsive.css: ../../docutils/writers/html5_polyglot/responsive.css
76 .. _custom style sheets: ../howto/html-stylesheets.html
77 .. _viewable with any browser: http://www.anybrowser.org/campaign
78 .. _Benefits of polyglot XHTML5: http://xmlplease.com/xhtml/xhtml5polyglot/
79 .. _image: ../ref/rst/directives.html#image
80 __ https://developer.mozilla.org/en-US/docs/Learn/Performance/Multimedia
81 #rendering_strategy_preventing_jank_when_loading_images
82
83
84 html4css1
85 ---------
86
87 :aliases: html4, html_, xhtml10
88 :front-end: rst2html4_
89 :config: `[html4css1 writer]`_
90
91 The HTML Writer module, ``docutils/writers/html4css1.py``, was the first
92 Docutils writer and up to release 0.13 the only official HTML writer.
93
94 The output conforms to the `XHTML 1 Transitional`_ specification. It does
95 not validate as `HTML 4.01 Transitional`_ due to the closing of empty tags
96 required in XML but not allowed in HTML 4. However, the output follows the
97 `HTML Compatibility Guidelines`_ for proper rendering on most HTML user
98 agents.
99
100 Correct rendering depends on a CSS_ style sheet. A reference style sheet,
101 `html4css1.css`_, is provided and used by default.
102
103 To support the `Internet Explorer` (with a market share of about 90%
104 around 2002, the time this writer was written), documents contain some
105 hard-coded formatting hints and are tagged as "text/html" (instead of
106 "application/xhtml+xml"). Additional class values serve as surrogate for
107 the "first"/"last" pseudo-classes introduced in CSS 2.1. [#IE]_
108
109 Tables are used for description lists, field lists, docinfo, footnotes,
110 and option lists. Videos and SVG images are wrapped in <object> elements
111 and cannot be embedded.
112
113 .. [#IE] Conformance to `CSS 2.1`_ has been added in IE 8 (2009), support
114 for XHTML in IE 9 (2011).
115
116 .. _rst2html: tools.html#rst2html
117 .. _rst2html4: tools.html#rst2html4
118 .. _[html4css1 writer]: config.html#html4css1-writer
119 .. _html4css1.css: ../../docutils/writers/html4css1/html4css1.css
120
121 pep_html
122 ~~~~~~~~
123
124 :front-end: ``docutils --reader=pep --writer=pep_html``
125 :config: `[pep_html writer]`_, `[html4css1 writer]`_
126
127 This is a special writer for the generation of `Python Enhancement
128 Proposals`_ (PEPs). It inherits from html4css1_ and adds some `PEP-specific
129 options`_, a style sheet and template. It works best in combination with
130 the specialised "pep_html" reader.
131
132 .. _PEP-specific options:
133 .. _[pep_html writer]: config.html#pep-html-writer
134 .. _Python Enhancement Proposals: https://peps.python.org/
135
136 s5_html
137 ~~~~~~~
138
139 :alias: s5
140 :front-end: rst2s5_
141 :config: `[s5_html writer]`_, `[html4css1 writer]`_
142
143 The `s5` writer inherits from html4css1_. It produces XHTML for use with
144 S5_, the “Simple Standards-based Slide Show System” by Eric Meyer. See
145 `Easy Slide Shows With reST & S5`_ for details.
146
147 .. _rst2s5: tools.html#rst2s5
148 .. _[s5_html writer]: config.html#s5-html-writer
149 .. _Easy Slide Shows With reST & S5: slide-shows.html
150 .. _S5: http://meyerweb.com/eric/tools/s5/
151 .. _theme: tools.html#themes
152
153
154 3rd-party HTML writers
155 ----------------------
156
157 For additional HTML writers, see the `Docutils link list`__
158 and the sandbox_.
159
160 __ https://docutils.sourceforge.io/docs/user/links.html
161 #website-generators-and-html-variants
162 .. _sandbox: ../dev/policies.html#the-sandbox
163
164
165 References
166 ----------
167
168 _`HTML Standard`
169 `HTML Living Standard`.
170 https://html.spec.whatwg.org/multipage/
171
172 _`XHTML 1 Transitional`
173 `Transitional version`_ of:
174 `XHTML™ 1.0 The Extensible HyperText Markup Language (Second
175 Edition)`, `A Reformulation of HTML 4 in XML 1.0`,
176 W3C Recommendation, 26 January 2000, revised 1 August 2002.
177 https://www.w3.org/TR/xhtml1/
178
179 _`HTML 4.01 Transitional`
180 Transitional version of:
181 `HTML 4.01 Specification`, W3C Recommendation 24 December 1999.
182 https://www.w3.org/TR/html4/
183
184 .. _`CSS 1`:
185
186 _`CSS Level 1`:
187 The features defined in the `CSS1 specification`_, but using the syntax
188 and definitions in the `CSS 2.1`_ specification.
189
190 _`CSS 2.1`
191 `Cascading Style Sheets Level 2 Revision 1 (CSS 2.1) Specification`,
192 W3C Recommendation 07 June 2011.
193 https://www.w3.org/TR/CSS21/
194
195 _`CSS 3`:
196 CSS Level 3 builds on CSS Level 2 module by module, using the CSS 2.1
197 specification as its core.
198
199 | Specifications: https://www.w3.org/Style/CSS/specs.en.html
200 | Validator: http://jigsaw.w3.org/css-validator/
201
202 .. other references
203 ----------------
204
205 .. _HTML Compatibility Guidelines: https://www.w3.org/TR/xhtml1/#guidelines
206 .. _transitional version:
207 https://www.w3.org/TR/xhtml1/#a_dtd_XHTML-1.0-Transitional
208
209 .. _polyglot HTML: https://www.w3.org/TR/html-polyglot/
210
211 .. Beware. This specification is no longer in active maintenance and the
212 HTML Working Group does not intend to maintain it further.
213
214 .. _CSS: https://www.w3.org/TR/CSS/
215 .. _CSS1 specification: https://www.w3.org/TR/2008/REC-CSS1-20080411/
216
217 .. Appendix
218
219
220 On the question of Polyglot markup, there seems to be little
221 consensus. One line of argument suggests that, to the extent that it
222 is practical to obey the Robustness principle, it makes sense to do
223 so. That is, if you're generating HTML markup for the web, and you can
224 generate Polyglot markup that is also directly consumable as XML, you
225 should do so. Another line of argument suggests that even under the
226 most optimistic of projections, so tiny a fraction of the web will
227 ever be written in Polyglot that there's no practical benefit to
228 pursuing it as a general strategy for consuming documents from the
229 web. If you want to consume HTML content, use an HTML parser that
230 produces an XML-compatible DOM or event stream.
231
232 -- https://www.w3.org/TR/html-xml-tf-report/#conclusions
233
234 Further development
235
236 On 2016-05-25, David Goodger wrote:
237
238 > In addition, I'd actually like to see the HTML writer(s) with
239 > fully-parameterized classes, i.e. removing hard-coded *classes* as well as
240 > formatting. This way, any user who wants to (e.g.) write reST for use with
241 > Bootstrap can easily work around any naming conflicts.
242
243 .. _front-end: tools.html