SF.net SVN: docutils:[9562 ] trunk/docutils

milde--- via Docutils-checkins <[email protected]>
Newsgroups gmane.text.docutils.cvs
Message-ID <[email protected]>
Revision: 9562
          http://sourceforge.net/p/docutils/code/9562
Author:   milde
Date:     2024-03-14 16:35:03 +0000 (Thu, 14 Mar 2024)
Log Message:
-----------
Link to the document top from the ToC heading.

Add a "back"-link to "#top" (unless toc_backlinks_ is False).
For the definition of "#top" see the HTML standard section
"Scrolling to a fragment"
https://html.spec.whatwg.org/multipage/browsing-the-web.html#scrolling-to-a-fragment
(point 10 in the second list).

Modified Paths:
--------------
    trunk/docutils/HISTORY.txt
    trunk/docutils/docutils/writers/_html_base.py
    trunk/docutils/docutils/writers/html5_polyglot/responsive.css
    trunk/docutils/test/functional/expected/misc_rst_html5.html
    trunk/docutils/test/functional/expected/pep_html.html
    trunk/docutils/test/functional/expected/standalone_rst_html4css1.html
    trunk/docutils/test/functional/expected/standalone_rst_html5.html

Modified: trunk/docutils/HISTORY.txt
===================================================================
--- trunk/docutils/HISTORY.txt	2024-03-14 16:34:48 UTC (rev 9561)
+++ trunk/docutils/HISTORY.txt	2024-03-14 16:35:03 UTC (rev 9562)
@@ -162,6 +162,8 @@
     (image transformations, math content conversion, ...).
   - Close ``<dt>`` element in `depart_term()` to allow a
     "definition_list_item" with multiple "terms" (cf. feature-request #60).
+  - Link to the document "#top" from the ToC heading
+    (unless toc_backlinks_ is False).
 
 * docutils/writers/latex2e/__init__.py
 
@@ -4391,6 +4393,7 @@
 .. _table_style: docs/user/config.html#table-style
 .. _theme: docs/user/config.html#theme
 .. _theme_url: docs/user/config.html#theme-url
+.. _toc_backlinks: docs/user/config.html#toc-backlinks
 .. _traceback: docs/user/config.html#traceback
 .. _use_bibtex: docs/user/config.html#use-bibtex
 .. _use_latex_abstract: docs/user/config.html#use-latex-abstract

Modified: trunk/docutils/docutils/writers/_html_base.py
===================================================================
--- trunk/docutils/docutils/writers/_html_base.py	2024-03-14 16:34:48 UTC (rev 9561)
+++ trunk/docutils/docutils/writers/_html_base.py	2024-03-14 16:35:03 UTC (rev 9562)
@@ -1745,6 +1745,10 @@
             # TODO: use role="heading" or <h1>? (HTML5 only)
             self.body.append(
                 self.starttag(node, 'p', '', CLASS='topic-title'))
+            if (self.settings.toc_backlinks
+                and 'contents' in node.parent['classes']):
+                self.body.append('<a class="reference internal" href="#top">')
+                close_tag = '</a></p>\n'
         elif isinstance(node.parent, nodes.sidebar):
             # TODO: use role="heading" or <h1>? (HTML5 only)
             self.body.append(
@@ -1753,8 +1757,7 @@
             self.body.append(
                   self.starttag(node, 'p', '', CLASS='admonition-title'))
         elif isinstance(node.parent, nodes.table):
-            self.body.append(
-                  self.starttag(node, 'caption', ''))
+            self.body.append(self.starttag(node, 'caption', ''))
             close_tag = '</caption>\n'
         elif isinstance(node.parent, nodes.document):
             self.body.append(self.starttag(node, 'h1', '', CLASS='title'))

Modified: trunk/docutils/docutils/writers/html5_polyglot/responsive.css
===================================================================
--- trunk/docutils/docutils/writers/html5_polyglot/responsive.css	2024-03-14 16:34:48 UTC (rev 9561)
+++ trunk/docutils/docutils/writers/html5_polyglot/responsive.css	2024-03-14 16:35:03 UTC (rev 9562)
@@ -276,7 +276,8 @@
 a:hover {
   text-decoration: underline;
 }
-*:hover > a.toc-backref:after {
+*:hover > a.toc-backref:after,
+.topic-title:hover > a:after {
   content: " \2191"; /* ↑ UPWARDS ARROW */
   color: grey;
 }

Modified: trunk/docutils/test/functional/expected/misc_rst_html5.html
===================================================================
--- trunk/docutils/test/functional/expected/misc_rst_html5.html	2024-03-14 16:34:48 UTC (rev 9561)
+++ trunk/docutils/test/functional/expected/misc_rst_html5.html	2024-03-14 16:35:03 UTC (rev 9562)
@@ -14,7 +14,7 @@
 <h1 class="title">Additional tests with HTML 5</h1>
 
 <nav class="contents" id="contents" role="doc-toc">
-<p class="topic-title">Contents</p>
+<p class="topic-title"><a class="reference internal" href="#top">Contents</a></p>
 <ul class="simple">
 <li><p><a class="reference internal" href="#section-heading-levels" id="toc-entry-1">Section heading levels</a></p></li>
 <li><p><a class="reference internal" href="#level-1" id="toc-entry-2">Level 1</a></p>

Modified: trunk/docutils/test/functional/expected/pep_html.html
===================================================================
--- trunk/docutils/test/functional/expected/pep_html.html	2024-03-14 16:34:48 UTC (rev 9561)
+++ trunk/docutils/test/functional/expected/pep_html.html	2024-03-14 16:35:03 UTC (rev 9562)
@@ -51,7 +51,7 @@
 </table>
 <hr />
 <div class="contents topic" id="contents">
-<p class="topic-title">Contents</p>
+<p class="topic-title"><a class="reference internal" href="#top">Contents</a></p>
 <ul class="simple">
 <li><a class="reference internal" href="#abstract" id="toc-entry-1">Abstract</a></li>
 <li><a class="reference internal" href="#copyright" id="toc-entry-2">Copyright</a></li>

Modified: trunk/docutils/test/functional/expected/standalone_rst_html4css1.html
===================================================================
--- trunk/docutils/test/functional/expected/standalone_rst_html4css1.html	2024-03-14 16:34:48 UTC (rev 9561)
+++ trunk/docutils/test/functional/expected/standalone_rst_html4css1.html	2024-03-14 16:35:03 UTC (rev 9562)
@@ -84,7 +84,7 @@
 They are transformed from section titles after parsing. -->
 <!-- bibliographic fields (which also require a transform): -->
 <div class="contents topic" id="table-of-contents">
-<p class="topic-title">Table of Contents</p>
+<p class="topic-title"><a class="reference internal" href="#top">Table of Contents</a></p>
 <ul class="auto-toc simple">
 <li><a class="reference internal" href="#structural-elements" id="toc-entry-1">1&nbsp;&nbsp;&nbsp;Structural Elements</a><ul class="auto-toc">
 <li><a class="reference internal" href="#section-title" id="toc-entry-2">1.1&nbsp;&nbsp;&nbsp;Section Title</a></li>

Modified: trunk/docutils/test/functional/expected/standalone_rst_html5.html
===================================================================
--- trunk/docutils/test/functional/expected/standalone_rst_html5.html	2024-03-14 16:34:48 UTC (rev 9561)
+++ trunk/docutils/test/functional/expected/standalone_rst_html5.html	2024-03-14 16:35:03 UTC (rev 9562)
@@ -83,7 +83,7 @@
 They are transformed from section titles after parsing. -->
 <!-- bibliographic fields (which also require a transform): -->
 <nav class="contents" id="table-of-contents" role="doc-toc">
-<p class="topic-title">Table of Contents</p>
+<p class="topic-title"><a class="reference internal" href="#top">Table of Contents</a></p>
 <ul class="auto-toc simple">
 <li><p><a class="reference internal" href="#structural-elements" id="toc-entry-1"><span class="sectnum">1 </span>Structural Elements</a></p>
 <ul class="auto-toc">

This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.



_______________________________________________
Docutils-checkins mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/docutils-checkins
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.