diff options
| author | milde <milde@929543f6-e4f2-0310-98a6-ba3bd3dd1d04> | 2015-03-11 15:55:43 +0000 |
|---|---|---|
| committer | milde <milde@929543f6-e4f2-0310-98a6-ba3bd3dd1d04> | 2015-03-11 15:55:43 +0000 |
| commit | 8d8f4cd077a9210a23e87f2fa4514fb16f808c2a (patch) | |
| tree | a3496040b0179af5932a9527e12fdf305e1968a4 | |
| parent | ce9356125402e102f27cd7bf4645f1022958a4ee (diff) | |
| download | docutils-8d8f4cd077a9210a23e87f2fa4514fb16f808c2a.tar.gz | |
Announce the new HTML writers. Small fixes to get valid HTML.
git-svn-id: http://svn.code.sf.net/p/docutils/code/trunk@7820 929543f6-e4f2-0310-98a6-ba3bd3dd1d04
| -rw-r--r-- | docutils/HISTORY.txt | 26 | ||||
| -rw-r--r-- | docutils/RELEASE-NOTES.txt | 16 | ||||
| -rw-r--r-- | docutils/docutils/writers/html_base/__init__.py | 37 | ||||
| -rw-r--r-- | docutils/test/functional/expected/standalone_rst_html_base.html | 40 | ||||
| -rw-r--r-- | docutils/test/functional/expected/standalone_rst_xhtml11.xhtml | 38 | ||||
| -rw-r--r-- | docutils/test/functional/input/standalone_rst_html_base.txt | 12 |
6 files changed, 94 insertions, 75 deletions
diff --git a/docutils/HISTORY.txt b/docutils/HISTORY.txt index 44f25ee83..82f699c5c 100644 --- a/docutils/HISTORY.txt +++ b/docutils/HISTORY.txt @@ -33,7 +33,16 @@ Changes Since 0.12 - Add ``\colon`` macro, fix spacing around colons. Fixes [ 246 ]. - New upstream version (additional macros, piecewise integrals and sums). - + +* docutils/writers/html_base/ + + - New HTML writer generating basic HTML (`polyglot markup`_ conforming to + both, `HTML 5`_ and `XHTML 1.0`_ (transitional)). + + New stylesheet ``html-base.css`` for default layout using CSS 2.1 rules. + + Also base for the `xhtml11` writer. + * docutils/writers/html4css1/__init__.py - Add "docutils" to class values for "container" object to address [ 267 ]. @@ -43,11 +52,9 @@ Changes Since 0.12 * docutils/writers/xhtml11/ - - New HTML writer generating `XHTML1.1`_ styled with CSS2.1 + - New HTML writer generating `XHTML 1.1`_ styled with CSS2.1 Moved to the docutils core from sandbox/html4strict. - .. _XHTML1.1: http://www.w3.org/TR/xhtml11/ - * docutils/writers/latex2e/__init__.py - use absolute path for ``default_template_path``. @@ -61,6 +68,17 @@ Changes Since 0.12 - Fix [ 262 ] Use ``\linewidth`` instead of ``\textwidth`` for figures, admonitions and docinfo. +* tools/ + + - New front-ends ``rst2xhtml.py`` and ``rst2html5.py`` for the + corresponding writers. + +.. _polyglot markup: http://www.w3.org/TR/html-polyglot/ +.. _HTML 5: http://www.w3.org/TR/html5/ +.. _XHTML 1.0: http://www.w3.org/TR/xhtml1/ +.. _XHTML 1.1: http://www.w3.org/TR/xhtml11/ + + Release 0.12 (2014-07-06) ========================= diff --git a/docutils/RELEASE-NOTES.txt b/docutils/RELEASE-NOTES.txt index ed87135ab..327f049f8 100644 --- a/docutils/RELEASE-NOTES.txt +++ b/docutils/RELEASE-NOTES.txt @@ -38,7 +38,7 @@ Future changes See `Porting Python 2 Code to Python 3`_ and `future: clean single-source support for Python 2/3`_ - - Drop support for python 2.4 after 0.12 release. + - Drop support for python 2.4 after release 0.12. .. _Porting Python 2 Code to Python 3: https://docs.python.org/3/howto/pyporting.html .. _future\: clean single-source support for Python 2/3: http://python-future.org @@ -46,6 +46,20 @@ Future changes Changes Since 0.12 ================== +* docutils/writers/ + + - New HTML writers generating `HTML 5`_ and `XHTML 1.1`_. + + New stylesheet ``html-base.css`` for default layout using CSS 2.1. + +* tools/ + + - New front-ends ``rst2xhtml.py`` and ``rst2html5.py`` for the + corresponding writers. + +.. _HTML 5: http://www.w3.org/TR/html5/ +.. _XHTML 1.1: http://www.w3.org/TR/xhtml11/ + Release 0.12 (2014-07-06) ========================= diff --git a/docutils/docutils/writers/html_base/__init__.py b/docutils/docutils/writers/html_base/__init__.py index bde5676ff..30c3e38f0 100644 --- a/docutils/docutils/writers/html_base/__init__.py +++ b/docutils/docutils/writers/html_base/__init__.py @@ -19,7 +19,7 @@ """ Basic HyperText Markup Language document tree Writer. -The output conforms to the `HTML 5` specification as well as +The output conforms to the `HTML 5` specification as well as to `XHTML 1.0 transitional`. The cascading style sheet "html-base.css" is required for proper viewing. @@ -298,7 +298,8 @@ class HTMLTranslator(nodes.NodeVisitor): def encode(self, text): """Encode special characters in `text` & return.""" - # @@@ A codec to do these and all other HTML entities would be nice. + # Use only named entities known in both XML and HTML + # other characters are automatically encoded "by number" if required. text = unicode(text) return text.translate({ ord('&'): u'&', @@ -432,10 +433,6 @@ class HTMLTranslator(nodes.NodeVisitor): return child['classes'].append(class_) - def set_first_last(self, node): - pass - # TODO: remove calls to this function - def visit_Text(self, node): text = node.astext() encoded = self.encode(text) @@ -471,12 +468,11 @@ class HTMLTranslator(nodes.NodeVisitor): def visit_admonition(self, node): node['classes'].insert(0, 'admonition') self.body.append(self.starttag(node, 'div')) - self.set_first_last(node) def depart_admonition(self, node=None): self.body.append('</div>\n') - attribution_formats = {'dash': ('—', ''), + attribution_formats = {'dash': (u'\u2014', ''), 'parentheses': ('(', ')'), 'parens': ('(', ')'), 'none': ('', '')} @@ -486,9 +482,10 @@ class HTMLTranslator(nodes.NodeVisitor): self.context.append(suffix) self.body.append( self.starttag(node, 'p', prefix, CLASS='attribution')) + self.body.append(self.starttag(node, 'cite', '')) def depart_attribution(self, node): - self.body.append(self.context.pop() + '</p>\n') + self.body.append('</cite>' + self.context.pop() + '</p>\n') # author, authors # --------------- @@ -699,7 +696,6 @@ class HTMLTranslator(nodes.NodeVisitor): def visit_definition(self, node): self.body.append('</dt>\n') self.body.append(self.starttag(node, 'dd', '')) - self.set_first_last(node) def depart_definition(self, node): self.body.append('</dd>\n') @@ -744,7 +740,7 @@ class HTMLTranslator(nodes.NodeVisitor): def depart_docinfo(self, node): self.body.append('</dl>\n') - + def visit_docinfo_item(self, node, name, meta=True): if meta: meta_tag = '<meta name="%s" content="%s" />\n' \ @@ -818,9 +814,9 @@ class HTMLTranslator(nodes.NodeVisitor): node.parent.column += node['morecols'] self.body.append(self.starttag(node, tagname, '', **atts)) self.context.append('</%s>\n' % tagname.lower()) - if len(node) == 0: # empty cell - self.body.append(' ') - self.set_first_last(node) + # TODO: why did the html4css1 writer insert an NBSP into empty cells? + # if len(node) == 0: # empty cell + # self.body.append(' ') # no-break space def depart_entry(self, node): self.body.append(self.context.pop()) @@ -905,6 +901,7 @@ class HTMLTranslator(nodes.NodeVisitor): # --------- # use definition list instead of table for footnote text + # TODO: use the new HTML5 element <aside>? (Also for footnote text) def visit_footnote(self, node): if not self.in_footnote_list: self.body.append('<dl class="footnote">\n') @@ -1134,9 +1131,13 @@ class HTMLTranslator(nodes.NodeVisitor): def visit_literal_block(self, node): self.body.append(self.starttag(node, 'pre', '', CLASS='literal-block')) + if 'code' in node.get('classes', []): + self.body.append('<code>') def depart_literal_block(self, node): - self.body.append('\n</pre>\n') + if 'code' in node.get('classes', []): + self.body.append('</code>') + self.body.append('</pre>\n') def visit_math(self, node, math_env=''): # If the method is called from visit_math_block(), math_env != ''. @@ -1401,7 +1402,6 @@ class HTMLTranslator(nodes.NodeVisitor): def visit_sidebar(self, node): self.body.append( self.starttag(node, 'div', CLASS='sidebar')) - self.set_first_last(node) self.in_sidebar = True def depart_sidebar(self, node): @@ -1612,6 +1612,7 @@ class HTMLTranslator(nodes.NodeVisitor): def depart_title_reference(self, node): self.body.append('</cite>') + # TODO: use the new HTML5 element <aside>? (Also for footnote text) def visit_topic(self, node): self.body.append(self.starttag(node, 'div', CLASS='topic')) self.topic_classes = node['classes'] @@ -1647,10 +1648,10 @@ class SimpleListChecker(nodes.GenericNodeVisitor): Here "simple" means a list item containing nothing other than a single paragraph, a simple list, or a paragraph followed by a simple list. - + This version also checks for simple field lists and docinfo. """ - + def default_visit(self, node): raise nodes.NodeFound diff --git a/docutils/test/functional/expected/standalone_rst_html_base.html b/docutils/test/functional/expected/standalone_rst_html_base.html index 6db990a27..8fe2ecb1b 100644 --- a/docutils/test/functional/expected/standalone_rst_html_base.html +++ b/docutils/test/functional/expected/standalone_rst_html_base.html @@ -352,13 +352,11 @@ the preceding paragraph (over there <span class="docutils literal"><span class=" <pre class="literal-block">if literal_block: text = 'is left as-is' spaces_and_linebreaks = 'are preserved' - markup_processing = None -</pre> + markup_processing = None</pre> <p>Or they can be quoted without indentation:</p> <pre class="literal-block">>> Great idea! > -> Why didn't I think of that? -</pre> +> Why didn't I think of that?</pre> </div> <div class="section" id="line-blocks"> <h2><a class="toc-backref" href="#id51"><span class="sectnum">2.8</span> Line Blocks</a></h2> @@ -443,7 +441,7 @@ as follows and begins now. All brontosauruses are thin at one end, much much thicker in the middle and then thin again at the far end. That is my theory, it is mine, and belongs to me and I own it, and what it is too.</p> -<p class="attribution">—Anne Elk (Miss)</p> +<p class="attribution">—<cite>Anne Elk (Miss)</cite></p> </blockquote> <p>The language of a quote (like any other object) can be specified by a class attribute:</p> @@ -756,8 +754,7 @@ allowed (e.g. inside a directive).</p> <p>Another compound statement:</p> <div class="compound"> <p class="compound-first">Compound 2, a literal block:</p> -<pre class="compound-middle literal-block">Compound 2, literal. -</pre> +<pre class="compound-middle literal-block">Compound 2, literal.</pre> <p class="compound-last">Compound 2, this is a test.</p> </div> <div class="compound"> @@ -765,8 +762,7 @@ allowed (e.g. inside a directive).</p> </div> <div class="compound"> <pre class="compound-first literal-block">Compound 4. -This one starts with a literal block. -</pre> +This one starts with a literal block.</pre> <p class="compound-last">Compound 4, a paragraph.</p> </div> <p>Now something <em>really</em> perverted -- a nested compound block. This is @@ -815,8 +811,7 @@ paragraph.</p></td> This line is indented. The next line is blank. Inline markup is supported, e.g. <em>emphasis</em>, <strong>strong</strong>, <span class="docutils literal">literal -text</span>, footnotes <a class="footnote-reference" href="#id8" id="id22">[1]</a>, <span class="target" id="hyperlink-targets">hyperlink targets</span>, and <a class="reference external" href="http://www.python.org/">references</a>. -</pre> +text</span>, footnotes <a class="footnote-reference" href="#id8" id="id22">[1]</a>, <span class="target" id="hyperlink-targets">hyperlink targets</span>, and <a class="reference external" href="http://www.python.org/">references</a>.</pre> </div> <div class="section" id="code"> <h3><a class="toc-backref" href="#id95"><span class="sectnum">2.14.9</span> Code</a></h3> @@ -826,14 +821,12 @@ syntax highlighter and can be formatted with a style sheet. (Code parsing is turned off using the <span class="docutils literal"><span class="pre">syntax-highlight</span></span> config setting in the test conversions in order to get identical results with/without installed Pygments highlighter.)</p> -<pre class="code python literal-block">print 'This is Python code.' -</pre> +<pre class="code python literal-block"><code>print 'This is Python code.'</code></pre> <p>The <span class="docutils literal"><span class="pre">:number-lines:</span></span> option (with optional start value) generates line numbers:</p> -<pre class="code python literal-block"><span class="ln"> 8 </span># print integers from 0 to 9: +<pre class="code python literal-block"><code><span class="ln"> 8 </span># print integers from 0 to 9: <span class="ln"> 9 </span>for i in range(10): -<span class="ln">10 </span> print i -</pre> +<span class="ln">10 </span> print i</code></pre> <p>For inline code snippets, there is the <cite>code</cite> role, which can be used directly (the code will not be parsed/tagged, as the language is not known) or as base for special code roles, e.g. the LaTeX code in the next @@ -842,9 +835,8 @@ paragraph.</p> <code class="tex">\alpha = f(x)</code> prints <span class="formula"><i>α</i> = <i>f</i>(<i>x</i>)</span>.</p> <p>The <span class="docutils literal">:code:</span> option of the <cite>include</cite> directive sets the included content as a code block, here the rst file <span class="docutils literal">header_footer.txt</span> with line numbers:</p> -<pre class="code rst literal-block"><span class="ln">1 </span>.. header:: Document header -<span class="ln">2 </span>.. footer:: Document footer -</pre> +<pre class="code rst literal-block"><code><span class="ln">1 </span>.. header:: Document header +<span class="ln">2 </span>.. footer:: Document footer</code></pre> </div> </div> <div class="section" id="substitution-definitions"> @@ -992,7 +984,7 @@ span rows.</p> <tr><td><p>body row 5</p></td> <td colspan="2"><p>Cells may also be empty: <span class="docutils literal"><span class="pre">--></span></span></p></td> -<td> </td> +<td></td> </tr> </tbody> </table> @@ -1053,8 +1045,7 @@ crunchy, now would it?</p></td> <style type="text/css"><!-- .green {color: green;} .sc {font-variant: small-caps;} - --></style> -</pre> + --></style></pre> <p><span class="green sc" lang="en-gb">British colourful text in small-caps</span>.</p> </li> </ul> @@ -1180,8 +1171,7 @@ this behaviour with the <a class="reference internal" href="#run-in">run-in</a> <dd><p>of the field name width is possible with CSS instead of the <cite>field-name-limit</cite> configuration setting, for example:</p> -<pre class="literal-block">dl.field-list > dd { margin-left: 6em; } -</pre> +<pre class="literal-block">dl.field-list > dd { margin-left: 6em; }</pre> </dd> </dl> <div class="section" id="styling-with-class-arguments"> @@ -1436,7 +1426,7 @@ section, "Docutils System Messages":</p> <div class="footer"> <hr class="footer" /> <p>Document footer</p> -<p><a class="reference external" href="http://validator.w3.org/check?uri=referer"><img alt="Conforms to HTML 5!" src="https://validator-suite.w3.org/icons/vs-blue-256.png" style="width: 88px; height: 31px;" /></a> <a class="reference external" href="http://jigsaw.w3.org/css-validator/check/referer"><img alt="Valid CSS 2.1!" src="http://jigsaw.w3.org/css-validator/images/vcss" style="width: 88px; height: 31px;" /></a></p> +<p><a class="reference external" href="http://www.w3.org/TR/html5/"><img alt="Conforms to HTML 5" src="http://www.w3.org/html/logo/badge/html5-badge-h-css3-semantics.png" style="width: 88px; height: 31px;" /></a> <a class="reference external" href="http://validator.w3.org/check?uri=referer"><img alt="Check validity!" src="https://validator-suite.w3.org/icons/vs-blue-256.png" style="width: 88px; height: 31px;" /></a> <a class="reference external" href="http://jigsaw.w3.org/css-validator/check/referer"><img alt="Valid CSS 2.1!" src="http://jigsaw.w3.org/css-validator/images/vcss" style="width: 88px; height: 31px;" /></a></p> </div> </body> diff --git a/docutils/test/functional/expected/standalone_rst_xhtml11.xhtml b/docutils/test/functional/expected/standalone_rst_xhtml11.xhtml index 521ef9acc..daf861f46 100644 --- a/docutils/test/functional/expected/standalone_rst_xhtml11.xhtml +++ b/docutils/test/functional/expected/standalone_rst_xhtml11.xhtml @@ -354,13 +354,11 @@ the preceding paragraph (over there <span class="docutils literal"><span class=" <pre class="literal-block">if literal_block: text = 'is left as-is' spaces_and_linebreaks = 'are preserved' - markup_processing = None -</pre> + markup_processing = None</pre> <p>Or they can be quoted without indentation:</p> <pre class="literal-block">>> Great idea! > -> Why didn't I think of that? -</pre> +> Why didn't I think of that?</pre> </div> <div class="section" id="line-blocks"> <h2><a class="toc-backref" href="#id51"><span class="sectnum">2.8</span> Line Blocks</a></h2> @@ -445,7 +443,7 @@ as follows and begins now. All brontosauruses are thin at one end, much much thicker in the middle and then thin again at the far end. That is my theory, it is mine, and belongs to me and I own it, and what it is too.</p> -<p class="attribution">—Anne Elk (Miss)</p> +<p class="attribution">—<cite>Anne Elk (Miss)</cite></p> </blockquote> <p>The language of a quote (like any other object) can be specified by a class attribute:</p> @@ -758,8 +756,7 @@ allowed (e.g. inside a directive).</p> <p>Another compound statement:</p> <div class="compound"> <p class="compound-first">Compound 2, a literal block:</p> -<pre class="compound-middle literal-block">Compound 2, literal. -</pre> +<pre class="compound-middle literal-block">Compound 2, literal.</pre> <p class="compound-last">Compound 2, this is a test.</p> </div> <div class="compound"> @@ -767,8 +764,7 @@ allowed (e.g. inside a directive).</p> </div> <div class="compound"> <pre class="compound-first literal-block">Compound 4. -This one starts with a literal block. -</pre> +This one starts with a literal block.</pre> <p class="compound-last">Compound 4, a paragraph.</p> </div> <p>Now something <em>really</em> perverted -- a nested compound block. This is @@ -817,8 +813,7 @@ paragraph.</p></td> This line is indented. The next line is blank. Inline markup is supported, e.g. <em>emphasis</em>, <strong>strong</strong>, <span class="docutils literal">literal -text</span>, footnotes <a class="footnote-reference" href="#id8" id="id22">[1]</a>, <span class="target" id="hyperlink-targets">hyperlink targets</span>, and <a class="reference external" href="http://www.python.org/">references</a>. -</pre> +text</span>, footnotes <a class="footnote-reference" href="#id8" id="id22">[1]</a>, <span class="target" id="hyperlink-targets">hyperlink targets</span>, and <a class="reference external" href="http://www.python.org/">references</a>.</pre> </div> <div class="section" id="code"> <h3><a class="toc-backref" href="#id96"><span class="sectnum">2.14.9</span> Code</a></h3> @@ -828,14 +823,12 @@ syntax highlighter and can be formatted with a style sheet. (Code parsing is turned off using the <span class="docutils literal"><span class="pre">syntax-highlight</span></span> config setting in the test conversions in order to get identical results with/without installed Pygments highlighter.)</p> -<pre class="code python literal-block">print 'This is Python code.' -</pre> +<pre class="code python literal-block"><code>print 'This is Python code.'</code></pre> <p>The <span class="docutils literal"><span class="pre">:number-lines:</span></span> option (with optional start value) generates line numbers:</p> -<pre class="code python literal-block"><span class="ln"> 8 </span># print integers from 0 to 9: +<pre class="code python literal-block"><code><span class="ln"> 8 </span># print integers from 0 to 9: <span class="ln"> 9 </span>for i in range(10): -<span class="ln">10 </span> print i -</pre> +<span class="ln">10 </span> print i</code></pre> <p>For inline code snippets, there is the <cite>code</cite> role, which can be used directly (the code will not be parsed/tagged, as the language is not known) or as base for special code roles, e.g. the LaTeX code in the next @@ -845,9 +838,8 @@ paragraph.</p> <mrow><mi>α</mi><mo>=</mo><mi>f</mi><mo>(</mo><mi>x</mi><mo>)</mo></mrow></math>.</p> <p>The <span class="docutils literal">:code:</span> option of the <cite>include</cite> directive sets the included content as a code block, here the rst file <span class="docutils literal">header_footer.txt</span> with line numbers:</p> -<pre class="code rst literal-block"><span class="ln">1 </span>.. header:: Document header -<span class="ln">2 </span>.. footer:: Document footer -</pre> +<pre class="code rst literal-block"><code><span class="ln">1 </span>.. header:: Document header +<span class="ln">2 </span>.. footer:: Document footer</code></pre> </div> </div> <div class="section" id="substitution-definitions"> @@ -995,7 +987,7 @@ span rows.</p> <tr><td><p>body row 5</p></td> <td colspan="2"><p>Cells may also be empty: <span class="docutils literal"><span class="pre">--></span></span></p></td> -<td> </td> +<td></td> </tr> </tbody> </table> @@ -1056,8 +1048,7 @@ crunchy, now would it?</p></td> <style type="text/css"><!-- .green {color: green;} .sc {font-variant: small-caps;} - --></style> -</pre> + --></style></pre> <p><span class="green sc" xml:lang="en-gb">British colourful text in small-caps</span>.</p> </li> </ul> @@ -1202,8 +1193,7 @@ suppress this behaviour with the <a class="reference internal" href="#run-in">ru <dd><p>of the field name width is possible with CSS instead of the <cite>field-name-limit</cite> configuration setting, for example:</p> -<pre class="literal-block">dl.field-list > dd { margin-left: 6em; } -</pre> +<pre class="literal-block">dl.field-list > dd { margin-left: 6em; }</pre> </dd> </dl> <div class="section" id="styling-with-class-arguments"> diff --git a/docutils/test/functional/input/standalone_rst_html_base.txt b/docutils/test/functional/input/standalone_rst_html_base.txt index 81b72b0bd..1ae91134d 100644 --- a/docutils/test/functional/input/standalone_rst_html_base.txt +++ b/docutils/test/functional/input/standalone_rst_html_base.txt @@ -202,7 +202,7 @@ Of course, also "booktabs" style tables can be numbered: Maths ----- -For maximal compatibility, the ``html-output`` setting defaults to »HTML«. +For maximal compatibility, the ``html-output`` setting defaults to »HTML«. (HTML 5 accepts also MathML and SVG as nested languages.) The linear mapping :math:`f: \mathbb{C}^{N}\longmapsto\mathbb{C}^{N}` @@ -219,12 +219,18 @@ transformation (DFT). .. include:: data/errors.txt -.. footer:: |validator| |valid-CSS2| +.. footer:: |HTML 5| |validator| |valid-CSS2| + +.. |HTML 5| image:: http://www.w3.org/html/logo/badge/html5-badge-h-css3-semantics.png + :height: 31 + :width: 88 + :alt: Conforms to HTML 5 + :target: http://www.w3.org/TR/html5/ .. |validator| image:: https://validator-suite.w3.org/icons/vs-blue-256.png :height: 31 :width: 88 - :alt: Conforms to HTML 5! + :alt: Check validity! :target: http://validator.w3.org/check?uri=referer .. |valid-CSS2| image:: http://jigsaw.w3.org/css-validator/images/vcss |
