summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormilde <milde@929543f6-e4f2-0310-98a6-ba3bd3dd1d04>2022-06-19 20:23:12 +0000
committermilde <milde@929543f6-e4f2-0310-98a6-ba3bd3dd1d04>2022-06-19 20:23:12 +0000
commite71e250c58b477e4ffbb2df406fa2fc61c17eaea (patch)
tree82179c9a75d302851ab4e65ecd15d3c790bc5c8c
parent1b56eb8a75ecf18990cfe7ce4a67d1db4bd331ac (diff)
downloaddocutils-e71e250c58b477e4ffbb2df406fa2fc61c17eaea.tar.gz
Add wrapper around groups of footnotes to facilitate styling as a list.
Adapt style sheets and tests. Cf. bug #450. git-svn-id: https://svn.code.sf.net/p/docutils/code/trunk@9081 929543f6-e4f2-0310-98a6-ba3bd3dd1d04
-rw-r--r--docutils/HISTORY.txt1
-rw-r--r--docutils/RELEASE-NOTES.txt8
-rw-r--r--docutils/docutils/writers/_html_base.py19
-rw-r--r--docutils/docutils/writers/html5_polyglot/plain.css12
-rw-r--r--docutils/docutils/writers/html5_polyglot/tuftig.css3
-rw-r--r--docutils/test/functional/expected/footnotes_html5.html6
-rw-r--r--docutils/test/functional/expected/rst_html5_tuftig.html2
-rw-r--r--docutils/test/functional/expected/standalone_rst_html5.html8
-rw-r--r--docutils/test/test_writers/test_html5_polyglot_parts.py4
9 files changed, 46 insertions, 17 deletions
diff --git a/docutils/HISTORY.txt b/docutils/HISTORY.txt
index 4e8e66acd..eadbad73a 100644
--- a/docutils/HISTORY.txt
+++ b/docutils/HISTORY.txt
@@ -96,6 +96,7 @@ Changes Since 0.18.1
- Add space before "charset" meta tag closing sequence.
- Remove class value "controls" from an `image` node with video content
after converting it to a "control" attribute of the <video> tag.
+ - Wrap groups of footnotes in an ``<aside>`` for easier styling.
* docutils/writers/pep_html/
diff --git a/docutils/RELEASE-NOTES.txt b/docutils/RELEASE-NOTES.txt
index 8bdeeaa15..7da2de2d5 100644
--- a/docutils/RELEASE-NOTES.txt
+++ b/docutils/RELEASE-NOTES.txt
@@ -112,6 +112,14 @@ Release 0.19b (unpublished)
* Drop support for Python 2.7, 3.5, and 3.6.
+* Output changes:
+
+ HTML5:
+ Wrap groups of footnotes in an ``<aside>`` for easier styling.
+
+ The CSS rule ``.footnote-list { display: contents; }`` can be used to
+ restore the behaviour of custom CSS styles.
+
* After package installation, the CLI commands ``python -m docutils`` and
``docutils`` start the `generic command line front end tool`__.
diff --git a/docutils/docutils/writers/_html_base.py b/docutils/docutils/writers/_html_base.py
index d0d2d58e8..ed08c2715 100644
--- a/docutils/docutils/writers/_html_base.py
+++ b/docutils/docutils/writers/_html_base.py
@@ -635,8 +635,8 @@ class HTMLTranslator(nodes.NodeVisitor):
def depart_citation(self, node):
self.body.append('</div>\n')
- next_node = node.next_node(descend=False, siblings=True)
- if not isinstance(next_node, type(node)):
+ if not isinstance(node.next_node(descend=False, siblings=True),
+ type(node)):
self.body.append('</div>\n')
# Use DPub role (overwritten in HTML4)
@@ -943,15 +943,22 @@ class HTMLTranslator(nodes.NodeVisitor):
self.body_suffix[:0] = footer
del self.body[start:]
- # use HTML5 element <aside> with ARIA role "note" for footnote text
- # (the html4css1 writer uses a table).
def visit_footnote(self, node):
- classes = [node.tagname, self.settings.footnote_references]
- self.body.append(self.starttag(node, 'aside', classes=classes,
+ # No native HTML element: use <aside> with ARIA role
+ # (html4css1 uses tables).
+ # Wrap groups of footnotes for easier styling.
+ label_style = self.settings.footnote_references # brackets/superscript
+ if not isinstance(node.previous_sibling(), type(node)):
+ self.body.append(f'<aside class="footnote-list {label_style}">\n')
+ self.body.append(self.starttag(node, 'aside',
+ classes=[node.tagname, label_style],
role="note"))
def depart_footnote(self, node):
self.body.append('</aside>\n')
+ if not isinstance(node.next_node(descend=False, siblings=True),
+ type(node)):
+ self.body.append('</aside>\n')
def visit_footnote_reference(self, node):
href = '#' + node['refid']
diff --git a/docutils/docutils/writers/html5_polyglot/plain.css b/docutils/docutils/writers/html5_polyglot/plain.css
index d6398c98a..c5aad5d7b 100644
--- a/docutils/docutils/writers/html5_polyglot/plain.css
+++ b/docutils/docutils/writers/html5_polyglot/plain.css
@@ -199,17 +199,9 @@ table.numbered > caption:before {
/* ----------------------- */
/* line on the left */
-.footnote {
+.footnote-list {
border-left: solid thin;
- padding-left: 2.1em;
- margin-bottom: 0;
-}
-.footnote + .footnote {
- padding-top: 0.5em;
- margin-top: 0;
-}
-.footnote.superscript {
- padding-left: 1.2em;
+ padding-left: 0.25em;
}
/* Directives */
diff --git a/docutils/docutils/writers/html5_polyglot/tuftig.css b/docutils/docutils/writers/html5_polyglot/tuftig.css
index 0774a737e..26e48c4aa 100644
--- a/docutils/docutils/writers/html5_polyglot/tuftig.css
+++ b/docutils/docutils/writers/html5_polyglot/tuftig.css
@@ -222,7 +222,8 @@ dl.description > dd:after {
}
/* Citation list (style as description list) */
-.citation-list {
+.citation-list,
+.footnote-list {
display: contents;
}
.citation {
diff --git a/docutils/test/functional/expected/footnotes_html5.html b/docutils/test/functional/expected/footnotes_html5.html
index 21e13f95b..5d9c1019b 100644
--- a/docutils/test/functional/expected/footnotes_html5.html
+++ b/docutils/test/functional/expected/footnotes_html5.html
@@ -14,6 +14,7 @@
<p>Paragraphs may contain footnote references (manually numbered<a class="footnote-reference superscript" href="#footnote-1" id="footnote-reference-1" role="doc-noteref"><span class="fn-bracket">[</span>1<span class="fn-bracket">]</span></a>, anonymous auto-numbered<a class="footnote-reference superscript" href="#footnote-2" id="footnote-reference-2" role="doc-noteref"><span class="fn-bracket">[</span>3<span class="fn-bracket">]</span></a>, labeled auto-numbered<a class="footnote-reference superscript" href="#label" id="footnote-reference-3" role="doc-noteref"><span class="fn-bracket">[</span>2<span class="fn-bracket">]</span></a>, or
symbolic<a class="footnote-reference superscript" href="#footnote-3" id="footnote-reference-4" role="doc-noteref"><span class="fn-bracket">[</span>*<span class="fn-bracket">]</span></a>) or citation references (<a class="citation-reference" href="#cit2002" id="citation-reference-1" role="doc-biblioref">[CIT2002]</a>, <a class="citation-reference" href="#du2015" id="citation-reference-2" role="doc-biblioref">[DU2015]</a>).</p>
+<aside class="footnote-list superscript">
<aside class="footnote superscript" id="footnote-1" role="note">
<span class="label"><span class="fn-bracket">[</span>1<span class="fn-bracket">]</span></span>
<span class="backrefs">(<a role="doc-backlink" href="#footnote-reference-1">1</a>,<a role="doc-backlink" href="#footnote-reference-5">2</a>)</span>
@@ -50,6 +51,7 @@ Here's a reference to the next footnote:<a class="footnote-reference superscript
<p>Here's an unreferenced footnote, with a reference to a
nonexistent footnote:<a class="footnote-reference superscript" href="#footnote-6" id="footnote-reference-8" role="doc-noteref"><span class="fn-bracket">[</span>5<span class="fn-bracket">]</span></a>.</p>
</aside>
+</aside>
<section id="citations">
<h2>Citations<a class="self-link" title="link to this section" href="#citations"></a></h2>
<div role="list" class="citation-list">
@@ -65,12 +67,15 @@ rendered separately and differently from footnotes.</p>
</div>
</div>
<p>Here's a reference to the above, <a class="citation-reference" href="#cit2002" id="citation-reference-3" role="doc-biblioref">[CIT2002]</a>.</p>
+<aside class="footnote-list superscript">
<aside class="footnote superscript" id="footnote-6" role="note">
<span class="label"><span class="fn-bracket">[</span><a role="doc-backlink" href="#footnote-reference-8">5</a><span class="fn-bracket">]</span></span>
<p>this footnote is missing in the standard example document.</p>
</aside>
+</aside>
<p>Footnotes may contain block elements like lists<a class="footnote-reference superscript" href="#footnote-7" id="footnote-reference-9" role="doc-noteref"><span class="fn-bracket">[</span>6<span class="fn-bracket">]</span></a><a class="footnote-reference superscript" href="#list-note" id="footnote-reference-10" role="doc-noteref"><span class="fn-bracket">[</span>7<span class="fn-bracket">]</span></a><a class="footnote-reference superscript" href="#footnote-8" id="footnote-reference-11" role="doc-noteref"><span class="fn-bracket">[</span>8<span class="fn-bracket">]</span></a>,
admonitions<a class="footnote-reference superscript" href="#footnote-9" id="footnote-reference-12" role="doc-noteref"><span class="fn-bracket">[</span>9<span class="fn-bracket">]</span></a>, or tables<a class="footnote-reference superscript" href="#footnote-10" id="footnote-reference-13" role="doc-noteref"><span class="fn-bracket">[</span>10<span class="fn-bracket">]</span></a>.</p>
+<aside class="footnote-list superscript">
<aside class="footnote superscript" id="footnote-7" role="note">
<span class="label"><span class="fn-bracket">[</span><a role="doc-backlink" href="#footnote-reference-9">6</a><span class="fn-bracket">]</span></span>
<ol class="arabic simple">
@@ -118,6 +123,7 @@ admonitions<a class="footnote-reference superscript" href="#footnote-9" id="foot
</tbody>
</table>
</aside>
+</aside>
<p>This<a class="footnote-reference superscript" href="#list-note" id="footnote-reference-14" role="doc-noteref"><span class="fn-bracket">[</span>7<span class="fn-bracket">]</span></a> is a second reference to the footnote containing
a bullet. list.</p>
</section>
diff --git a/docutils/test/functional/expected/rst_html5_tuftig.html b/docutils/test/functional/expected/rst_html5_tuftig.html
index d0c954651..ecc85f6b4 100644
--- a/docutils/test/functional/expected/rst_html5_tuftig.html
+++ b/docutils/test/functional/expected/rst_html5_tuftig.html
@@ -127,11 +127,13 @@ Leipzig, 1998.</p>
</tr>
</tbody>
</table>
+<aside class="footnote-list superscript">
<aside class="footnote superscript align-left" id="not-in-margin" role="note">
<span class="label"><span class="fn-bracket">[</span>1<span class="fn-bracket">]</span></span>
<p>The “align-left” class value ensures this footnote is set
in the main text area.</p>
</aside>
+</aside>
</section>
</main>
<footer>
diff --git a/docutils/test/functional/expected/standalone_rst_html5.html b/docutils/test/functional/expected/standalone_rst_html5.html
index 5863cb14c..4832657ce 100644
--- a/docutils/test/functional/expected/standalone_rst_html5.html
+++ b/docutils/test/functional/expected/standalone_rst_html5.html
@@ -471,6 +471,7 @@ Python-specific usage examples; begun with &quot;&gt;&gt;&gt;&quot;
</section>
<section id="footnotes">
<h3><a class="toc-backref" href="#toc-entry-17" role="doc-backlink"><span class="sectnum">2.11 </span>Footnotes</a></h3>
+<aside class="footnote-list brackets">
<aside class="footnote brackets" id="footnote-1" role="note">
<span class="label"><span class="fn-bracket">[</span>1<span class="fn-bracket">]</span></span>
<span class="backrefs">(<a role="doc-backlink" href="#footnote-reference-1">1</a>,<a role="doc-backlink" href="#footnote-reference-5">2</a>,<a role="doc-backlink" href="#footnote-reference-9">3</a>)</span>
@@ -507,6 +508,7 @@ Here's a reference to the next footnote: <a class="footnote-reference brackets"
<p>Here's an unreferenced footnote, with a reference to a
nonexistent footnote: <a href="#system-message-2"><span class="problematic" id="footnote-reference-8">[5]_</span></a>.</p>
</aside>
+</aside>
</section>
<section id="citations">
<h3><a class="toc-backref" href="#toc-entry-18" role="doc-backlink"><span class="sectnum">2.12 </span>Citations</a></h3>
@@ -823,6 +825,7 @@ allowed (e.g. inside a directive).</p>
</section>
<section id="target-footnotes">
<h4><a class="toc-backref" href="#toc-entry-59" role="doc-backlink"><span class="sectnum">2.14.6 </span>Target Footnotes</a></h4>
+<aside class="footnote-list brackets">
<aside class="footnote brackets" id="footnote-7" role="note">
<span class="label"><span class="fn-bracket">[</span>7<span class="fn-bracket">]</span></span>
<span class="backrefs">(<a role="doc-backlink" href="#footnote-reference-18">1</a>,<a role="doc-backlink" href="#footnote-reference-19">2</a>,<a role="doc-backlink" href="#footnote-reference-20">3</a>,<a role="doc-backlink" href="#footnote-reference-26">4</a>)</span>
@@ -876,6 +879,7 @@ allowed (e.g. inside a directive).</p>
<span class="label"><span class="fn-bracket">[</span><a role="doc-backlink" href="#footnote-reference-33">19</a><span class="fn-bracket">]</span></span>
<p><a class="reference external" href="https://html.spec.whatwg.org/multipage/edits.html">https://html.spec.whatwg.org/multipage/edits.html</a></p>
</aside>
+</aside>
</section>
<section id="replacement-text">
<h4><a class="toc-backref" href="#toc-entry-60" role="doc-backlink"><span class="sectnum">2.14.7 </span>Replacement Text</a></h4>
@@ -1581,10 +1585,12 @@ chemicals.</p>
<cite>acronymes</cite>. In HTML, the &lt;acronym&gt; tag is obsolete and authors are
advised to use &lt;abbr&gt; instead. The HTML5 writer uses &lt;abbr&gt; for Docutil's
&lt;abbreviation&gt; element.</p>
+<aside class="footnote-list brackets">
<aside class="footnote brackets" id="footnote-6" role="note">
<span class="label"><span class="fn-bracket">[</span><a role="doc-backlink" href="#footnote-reference-11">‡</a><span class="fn-bracket">]</span></span>
<p>Irish Organic Farmers and Growers Association</p>
</aside>
+</aside>
</dd>
<dt>ruby, rt, rp</dt>
<dd><p>Ruby annotations</p>
@@ -1710,6 +1716,7 @@ a substitution.</p>
</blockquote>
</dd>
</dl>
+<aside class="footnote-list brackets">
<aside class="footnote brackets" id="attribute-optional" role="note">
<span class="label"><span class="fn-bracket">[</span>5<span class="fn-bracket">]</span></span>
<span class="backrefs">(<a role="doc-backlink" href="#footnote-reference-10">1</a>,<a role="doc-backlink" href="#footnote-reference-14">2</a>,<a role="doc-backlink" href="#footnote-reference-16">3</a>,<a role="doc-backlink" href="#footnote-reference-17">4</a>)</span>
@@ -1722,6 +1729,7 @@ to inline roles. See <a class="reference external" href="https://docutils.source
<p>Requires support for attributes to inline
roles to make sense.</p>
</aside>
+</aside>
</section>
<section id="indicating-edits">
<h3><a class="toc-backref" href="#toc-entry-52" role="doc-backlink"><span class="sectnum">3.4 </span>Indicating Edits</a></h3>
diff --git a/docutils/test/test_writers/test_html5_polyglot_parts.py b/docutils/test/test_writers/test_html5_polyglot_parts.py
index 6ae42f093..68ccc3eaf 100644
--- a/docutils/test/test_writers/test_html5_polyglot_parts.py
+++ b/docutils/test/test_writers/test_html5_polyglot_parts.py
@@ -675,6 +675,7 @@ The latter are referenced a second time [#f2]_ [twice]_.
{'fragment': '''\
<p>Two footnotes <a class="footnote-reference brackets" href="#f1" id="footnote-reference-1" role="doc-noteref"><span class="fn-bracket">[</span>1<span class="fn-bracket">]</span></a> <a class="footnote-reference brackets" href="#f2" id="footnote-reference-2" role="doc-noteref"><span class="fn-bracket">[</span>2<span class="fn-bracket">]</span></a> and two citations <a class="citation-reference" href="#once" id="citation-reference-1" role="doc-biblioref">[once]</a> <a class="citation-reference" href="#twice" id="citation-reference-2" role="doc-biblioref">[twice]</a>.</p>
<p>The latter are referenced a second time <a class="footnote-reference brackets" href="#f2" id="footnote-reference-3" role="doc-noteref"><span class="fn-bracket">[</span>2<span class="fn-bracket">]</span></a> <a class="citation-reference" href="#twice" id="citation-reference-3" role="doc-biblioref">[twice]</a>.</p>
+<aside class="footnote-list brackets">
<aside class="footnote brackets" id="f1" role="note">
<span class="label"><span class="fn-bracket">[</span>1<span class="fn-bracket">]</span></span>
<p>referenced once</p>
@@ -683,6 +684,7 @@ The latter are referenced a second time [#f2]_ [twice]_.
<span class="label"><span class="fn-bracket">[</span>2<span class="fn-bracket">]</span></span>
<p>referenced twice</p>
</aside>
+</aside>
<div role="list" class="citation-list">
<div class="citation" id="once" role="doc-biblioentry">
<span class="label"><span class="fn-bracket">[</span>once<span class="fn-bracket">]</span></span>
@@ -697,6 +699,7 @@ The latter are referenced a second time [#f2]_ [twice]_.
<main>
<p>Two footnotes <a class="footnote-reference brackets" href="#f1" id="footnote-reference-1" role="doc-noteref"><span class="fn-bracket">[</span>1<span class="fn-bracket">]</span></a> <a class="footnote-reference brackets" href="#f2" id="footnote-reference-2" role="doc-noteref"><span class="fn-bracket">[</span>2<span class="fn-bracket">]</span></a> and two citations <a class="citation-reference" href="#once" id="citation-reference-1" role="doc-biblioref">[once]</a> <a class="citation-reference" href="#twice" id="citation-reference-2" role="doc-biblioref">[twice]</a>.</p>
<p>The latter are referenced a second time <a class="footnote-reference brackets" href="#f2" id="footnote-reference-3" role="doc-noteref"><span class="fn-bracket">[</span>2<span class="fn-bracket">]</span></a> <a class="citation-reference" href="#twice" id="citation-reference-3" role="doc-biblioref">[twice]</a>.</p>
+<aside class="footnote-list brackets">
<aside class="footnote brackets" id="f1" role="note">
<span class="label"><span class="fn-bracket">[</span>1<span class="fn-bracket">]</span></span>
<p>referenced once</p>
@@ -705,6 +708,7 @@ The latter are referenced a second time [#f2]_ [twice]_.
<span class="label"><span class="fn-bracket">[</span>2<span class="fn-bracket">]</span></span>
<p>referenced twice</p>
</aside>
+</aside>
<div role="list" class="citation-list">
<div class="citation" id="once" role="doc-biblioentry">
<span class="label"><span class="fn-bracket">[</span>once<span class="fn-bracket">]</span></span>