|
From: <mi...@us...> - 2020-01-30 00:44:43
|
Revision: 8474
http://sourceforge.net/p/docutils/code/8474
Author: milde
Date: 2020-01-30 00:44:40 +0000 (Thu, 30 Jan 2020)
Log Message:
-----------
Use new HTML5 element <main>.
Modified Paths:
--------------
trunk/docutils/docutils/writers/_html_base.py
trunk/docutils/docutils/writers/html5_polyglot/__init__.py
trunk/docutils/test/functional/expected/footnotes_html5.html
trunk/docutils/test/functional/expected/math_output_mathml.xhtml
trunk/docutils/test/functional/expected/standalone_rst_html5.html
trunk/docutils/test/test_writers/test_html5_polyglot_parts.py
Modified: trunk/docutils/docutils/writers/_html_base.py
===================================================================
--- trunk/docutils/docutils/writers/_html_base.py 2020-01-30 00:44:27 UTC (rev 8473)
+++ trunk/docutils/docutils/writers/_html_base.py 2020-01-30 00:44:40 UTC (rev 8474)
@@ -720,7 +720,6 @@
or 'docutils document without title')
self.head.append('<title>%s</title>\n' % self.encode(title))
- # TODO: use new HTML5 element <main>?
def depart_document(self, node):
self.head_prefix.extend([self.doctype,
self.head_prefix_template %
Modified: trunk/docutils/docutils/writers/html5_polyglot/__init__.py
===================================================================
--- trunk/docutils/docutils/writers/html5_polyglot/__init__.py 2020-01-30 00:44:27 UTC (rev 8473)
+++ trunk/docutils/docutils/writers/html5_polyglot/__init__.py 2020-01-30 00:44:40 UTC (rev 8474)
@@ -201,6 +201,36 @@
def depart_date(self, node):
self.depart_docinfo_item()
+ def visit_document(self, node):
+ title = (node.get('title', '') or os.path.basename(node['source'])
+ or 'untitled Docutils document')
+ self.head.append('<title>%s</title>\n' % self.encode(title))
+
+ def depart_document(self, node):
+ self.head_prefix.extend([self.doctype,
+ self.head_prefix_template %
+ {'lang': self.settings.language_code}])
+ self.html_prolog.append(self.doctype)
+ self.meta.insert(0, self.content_type % self.settings.output_encoding)
+ self.head.insert(0, self.content_type % self.settings.output_encoding)
+ if 'name="dcterms.' in ''.join(self.meta):
+ self.head.append(
+ '<link rel="schema.dcterms" href="http://purl.org/dc/terms/">')
+ if self.math_header:
+ if self.math_output == 'mathjax':
+ self.head.extend(self.math_header)
+ else:
+ self.stylesheet.extend(self.math_header)
+ # skip content-type meta tag with interpolated charset value:
+ self.html_head.extend(self.head[1:])
+ self.body_prefix.append(self.starttag(node, 'main'))
+ self.body_suffix.insert(0, '</main>\n')
+ self.fragment.extend(self.body) # self.fragment is the "naked" body
+ self.html_body.extend(self.body_prefix[1:] + self.body_pre_docinfo
+ + self.docinfo + self.body
+ + self.body_suffix[:-1])
+ assert not self.context, 'len(context) = %s' % len(self.context)
+
# use new HTML5 <figure> and <figcaption> elements
def visit_figure(self, node):
atts = {}
Modified: trunk/docutils/test/functional/expected/footnotes_html5.html
===================================================================
--- trunk/docutils/test/functional/expected/footnotes_html5.html 2020-01-30 00:44:27 UTC (rev 8473)
+++ trunk/docutils/test/functional/expected/footnotes_html5.html 2020-01-30 00:44:40 UTC (rev 8474)
@@ -8,7 +8,7 @@
<link rel="stylesheet" href="../input/data/plain.css" type="text/css" />
</head>
<body>
-<div class="document" id="test-footnote-and-citation-rendering">
+<main id="test-footnote-and-citation-rendering">
<h1 class="title">Test footnote and citation rendering</h1>
<p>Paragraphs may contain footnote references (manually numbered<a class="footnote-reference superscript" href="#footnote-1" id="footnote-reference-1">1</a>, anonymous auto-numbered<a class="footnote-reference superscript" href="#footnote-2" id="footnote-reference-2">3</a>, labeled auto-numbered<a class="footnote-reference superscript" href="#label" id="footnote-reference-3">2</a>, or
@@ -61,6 +61,6 @@
</dd>
</dl>
</section>
-</div>
+</main>
</body>
</html>
Modified: trunk/docutils/test/functional/expected/math_output_mathml.xhtml
===================================================================
--- trunk/docutils/test/functional/expected/math_output_mathml.xhtml 2020-01-30 00:44:27 UTC (rev 8473)
+++ trunk/docutils/test/functional/expected/math_output_mathml.xhtml 2020-01-30 00:44:40 UTC (rev 8474)
@@ -8,7 +8,7 @@
<link rel="stylesheet" href="../input/data/plain.css" type="text/css" />
</head>
<body>
-<div class="document" id="mathematics">
+<main id="mathematics">
<h1 class="title">Mathematics</h1>
<p>Docutils supports inline math with the prefix or postfix <span class="docutils literal">:math:</span>
@@ -215,6 +215,6 @@
\end{cases}
</pre>
</div>
-</div>
+</main>
</body>
</html>
Modified: trunk/docutils/test/functional/expected/standalone_rst_html5.html
===================================================================
--- trunk/docutils/test/functional/expected/standalone_rst_html5.html 2020-01-30 00:44:27 UTC (rev 8473)
+++ trunk/docutils/test/functional/expected/standalone_rst_html5.html 2020-01-30 00:44:40 UTC (rev 8474)
@@ -21,7 +21,7 @@
<header>
<p>Document header</p>
</header>
-<div class="document" id="restructuredtext-test-document">
+<main id="restructuredtext-test-document">
<span id="doctitle"></span>
<h1 class="title">reStructuredText Test Document</h1>
<p class="subtitle" id="examples-of-syntax-constructs"><span id="subtitle"></span>Examples of Syntax Constructs</p>
@@ -1830,7 +1830,7 @@
<p>Duplicate target name, cannot be used as a unique reference: "duplicate target names".</p>
</div>
</section>
-</div>
+</main>
<footer>
<p>Document footer</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://www.w3.org/Icons/ValidatorSuite/vs-blue-190.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>
Modified: trunk/docutils/test/test_writers/test_html5_polyglot_parts.py
===================================================================
--- trunk/docutils/test/test_writers/test_html5_polyglot_parts.py 2020-01-30 00:44:27 UTC (rev 8473)
+++ trunk/docutils/test/test_writers/test_html5_polyglot_parts.py 2020-01-30 00:44:40 UTC (rev 8474)
@@ -54,9 +54,9 @@
""",
"""\
{'fragment': '''<p>Simple String</p>\\n''',
- 'html_body': '''<div class="document">
+ 'html_body': '''<main>
<p>Simple String</p>
-</div>\\n''',
+</main>\\n''',
'html_head': '''...<title><string></title>\\n'''}
"""],
["""\
@@ -64,9 +64,9 @@
""",
"""\
{'fragment': '''<p>Simple String with <em>markup</em></p>\\n''',
- 'html_body': '''<div class="document">
+ 'html_body': '''<main>
<p>Simple String with <em>markup</em></p>
-</div>\\n''',
+</main>\\n''',
'html_head': '''...<title><string></title>\\n'''}
"""],
["""\
@@ -74,9 +74,9 @@
""",
"""\
{'fragment': '''<p>Simple String with an even simpler <span class="docutils literal">inline literal</span></p>\\n''',
- 'html_body': '''<div class="document">
+ 'html_body': '''<main>
<p>Simple String with an even simpler <span class="docutils literal">inline literal</span></p>
-</div>\\n''',
+</main>\\n''',
'html_head': '''...<title><string></title>\\n'''}
"""],
["""\
@@ -86,9 +86,9 @@
""",
"""\
{'fragment': '''<p>A simple <a class="reference external" href="http://www.test.com/test_url">anonymous reference</a></p>\\n''',
- 'html_body': '''<div class="document">
+ 'html_body': '''<main>
<p>A simple <a class="reference external" href="http://www.test.com/test_url">anonymous reference</a></p>
-</div>\\n''',
+</main>\\n''',
'html_head': '''...<title><string></title>\\n'''}
"""],
["""\
@@ -99,10 +99,10 @@
"""\
{'fragment': '''<p>One paragraph.</p>
<p>Two paragraphs.</p>\\n''',
- 'html_body': '''<div class="document">
+ 'html_body': '''<main>
<p>One paragraph.</p>
<p>Two paragraphs.</p>
-</div>\\n''',
+</main>\\n''',
'html_head': '''...<title><string></title>\\n'''}
"""],
["""\
@@ -114,10 +114,10 @@
"""\
{'fragment': '''<p>A simple <a class="reference external" href="http://www.test.com/test_url">named reference</a> with stuff in between the
reference and the target.</p>\\n''',
- 'html_body': '''<div class="document">
+ 'html_body': '''<main>
<p>A simple <a class="reference external" href="http://www.test.com/test_url">named reference</a> with stuff in between the
reference and the target.</p>
-</div>\\n''',
+</main>\\n''',
'html_head': '''...<title><string></title>\\n'''}
"""],
["""\
@@ -150,7 +150,7 @@
<p>And even more stuff</p>
</section>
</section>\\n''',
- 'html_body': '''<div class="document" id="title">
+ 'html_body': '''<main id="title">
<h1 class="title">Title</h1>
<p class="subtitle" id="subtitle">Subtitle</p>
<p>Some stuff</p>
@@ -162,7 +162,7 @@
<p>And even more stuff</p>
</section>
</section>
-</div>\\n''',
+</main>\\n''',
'html_head': '''...<title>Title</title>\\n''',
'html_subtitle': '''<p class="subtitle" id="subtitle">Subtitle</p>\\n''',
'html_title': '''<h1 class="title">Title</h1>\\n''',
@@ -184,7 +184,7 @@
<dd class="author"><p>me</p></dd>
</dl>\\n''',
'fragment': '''<p>Some stuff</p>\\n''',
- 'html_body': '''<div class="document" id="title">
+ 'html_body': '''<main id="title">
<h1 class="title">Title</h1>
<dl class="docinfo simple">
<dt class="author">Author</dt>
@@ -191,7 +191,7 @@
<dd class="author"><p>me</p></dd>
</dl>
<p>Some stuff</p>
-</div>\\n''',
+</main>\\n''',
'html_head': '''...<title>Title</title>
<meta name="author" content="me" />\\n''',
'html_title': '''<h1 class="title">Title</h1>\\n''',
@@ -208,9 +208,9 @@
""",
"""\
{'fragment': '''<p>Simple String</p>\\n''',
- 'html_body': '''<div class="document">
+ 'html_body': '''<main>
<p>Simple String</p>
-</div>\\n''',
+</main>\\n''',
'html_head': '''...<title><string></title>\\n'''}
"""],
["""\
@@ -218,9 +218,9 @@
""",
"""\
{'fragment': '''<p>Simple String with <em>markup</em></p>\\n''',
- 'html_body': '''<div class="document">
+ 'html_body': '''<main>
<p>Simple String with <em>markup</em></p>
-</div>\\n''',
+</main>\\n''',
'html_head': '''...<title><string></title>\\n'''}
"""],
["""\
@@ -228,9 +228,9 @@
""",
"""\
{'fragment': '''<p>Simple String with an even simpler <span class="docutils literal">inline literal</span></p>\\n''',
- 'html_body': '''<div class="document">
+ 'html_body': '''<main>
<p>Simple String with an even simpler <span class="docutils literal">inline literal</span></p>
-</div>\\n''',
+</main>\\n''',
'html_head': '''...<title><string></title>\\n'''}
"""],
["""\
@@ -240,9 +240,9 @@
""",
"""\
{'fragment': '''<p>A simple <a class="reference external" href="http://www.test.com/test_url">anonymous reference</a></p>\\n''',
- 'html_body': '''<div class="document">
+ 'html_body': '''<main>
<p>A simple <a class="reference external" href="http://www.test.com/test_url">anonymous reference</a></p>
-</div>\\n''',
+</main>\\n''',
'html_head': '''...<title><string></title>\\n'''}
"""],
["""\
@@ -254,10 +254,10 @@
"""\
{'fragment': '''<p>A simple <a class="reference external" href="http://www.test.com/test_url">named reference</a> with stuff in between the
reference and the target.</p>\\n''',
- 'html_body': '''<div class="document">
+ 'html_body': '''<main>
<p>A simple <a class="reference external" href="http://www.test.com/test_url">named reference</a> with stuff in between the
reference and the target.</p>
-</div>\\n''',
+</main>\\n''',
'html_head': '''...<title><string></title>\\n'''}
"""],
["""\
@@ -296,7 +296,7 @@
</section>
</section>
</section>\\n''',
- 'html_body': '''<div class="document">
+ 'html_body': '''<main>
<section id="title">
<h1>Title</h1>
<section id="not-a-subtitle">
@@ -312,7 +312,7 @@
</section>
</section>
</section>
-</div>\\n''',
+</main>\\n''',
'html_head': '''...<title><string></title>\\n'''}
"""],
["""\
@@ -324,12 +324,12 @@
<li><p>bullet</p></li>
<li><p>list</p></li>
</ul>\\n''',
- 'html_body': '''<div class="document">
+ 'html_body': '''<main>
<ul class="simple">
<li><p>bullet</p></li>
<li><p>list</p></li>
</ul>
-</div>\\n''',
+</main>\\n''',
'html_head': '''...<title><string></title>\\n'''}
"""],
["""\
@@ -357,7 +357,7 @@
</tr>
</tbody>
</table>\\n''',
- 'html_body': '''<div class="document">
+ 'html_body': '''<main>
<table class="align-right">
<colgroup>
<col style="width: 50%%" />
@@ -372,7 +372,7 @@
</tr>
</tbody>
</table>
-</div>\\n''',
+</main>\\n''',
'html_head': '''...<title><string></title>\\n'''}
"""],
["""\
@@ -399,7 +399,7 @@
<dd><p>list</p>
</dd>
</dl>\\n''',
- 'html_body': '''<div class="document">
+ 'html_body': '''<main>
<p>Not a docinfo.</p>
<dl class="field-list simple">
<dt>This</dt>
@@ -413,7 +413,7 @@
<dd><p>list</p>
</dd>
</dl>
-</div>\\n''',
+</main>\\n''',
'html_head': '''...<title><string></title>\\n'''}
"""],
["""\
@@ -434,7 +434,7 @@
</dd>
</dl>\\n''',
'html_body': '''\
-<div class="document">
+<main>
<p>Not a docinfo.</p>
<dl class="field-list simple">
<dt>This is</dt>
@@ -444,7 +444,7 @@
<dd><p>names</p>
</dd>
</dl>
-</div>\\n''',
+</main>\\n''',
'html_head': '''...<title><string></title>\\n'''}
"""],
["""\
@@ -469,7 +469,7 @@
</figcaption>
</figure>\\n''',
'html_body': '''\
-<div class="document">
+<main>
<figure>
<img alt="dummy.png" src="dummy.png" />
<figcaption>
@@ -480,7 +480,7 @@
</div>
</figcaption>
</figure>
-</div>\\n''',
+</main>\\n''',
'html_head': '''...<title><string></title>\\n'''}
"""],
["""\
@@ -497,7 +497,7 @@
</figcaption>
</figure>\\n''',
'html_body': '''\
-<div class="document">
+<main>
<figure>
<img alt="dummy.png" src="dummy.png" />
<figcaption>
@@ -504,7 +504,7 @@
<p>The figure's caption, no legend.</p>
</figcaption>
</figure>
-</div>\\n''',
+</main>\\n''',
'html_head': '''...<title><string></title>\\n'''}
"""],
["""\
@@ -525,7 +525,7 @@
</figcaption>
</figure>\\n''',
'html_body': '''\
-<div class="document">
+<main>
<figure>
<img alt="dummy.png" src="dummy.png" />
<figcaption>
@@ -534,7 +534,7 @@
</div>
</figcaption>
</figure>
-</div>\\n''',
+</main>\\n''',
'html_head': '''...<title><string></title>\\n'''}
"""],
])
@@ -550,12 +550,12 @@
</figure>
<p>No caption nor legend.</p>\\n''',
'html_body': '''\
-<div class="document">
+<main>
<figure>
<img alt="dummy.png" src="dummy.png" />
</figure>
<p>No caption nor legend.</p>
-</div>\\n''',
+</main>\\n''',
'html_head': '''...<title><string></title>\\n'''}
"""],
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|