|
From: <mi...@us...> - 2026-06-27 17:25:09
|
Revision: 10373
http://sourceforge.net/p/docutils/code/10373
Author: milde
Date: 2026-06-27 17:25:07 +0000 (Sat, 27 Jun 2026)
Log Message:
-----------
Imrove readability of generated HTML5 document source.
Add newlines to the `<span>` elements used for additional IDs
if the context allows. Makes affected section title lines a bit shorter.
Modified Paths:
--------------
trunk/docutils/HISTORY.rst
trunk/docutils/docutils/writers/_html_base.py
trunk/docutils/test/functional/expected/misc_rst_html4css1.html
trunk/docutils/test/functional/expected/misc_rst_html5.html
trunk/docutils/test/functional/expected/standalone_rst_html4css1.html
trunk/docutils/test/functional/expected/standalone_rst_html5.html
Modified: trunk/docutils/HISTORY.rst
===================================================================
--- trunk/docutils/HISTORY.rst 2026-06-26 10:26:58 UTC (rev 10372)
+++ trunk/docutils/HISTORY.rst 2026-06-27 17:25:07 UTC (rev 10373)
@@ -520,6 +520,9 @@
- Add "px" to unitless table "width" values.
- Fix error when determining the document metadata title from the
source path and the internal `source` attribute is None.
+ - `HTMLTranslator.starttag()`: Add newlines to the `<span>` elements
+ used for additional IDs if the `suffix` argument starts with "\n"
+ (indicating that it is OK to add whitespace).
* docutils/writers/html4css1/__init__.py
Modified: trunk/docutils/docutils/writers/_html_base.py
===================================================================
--- trunk/docutils/docutils/writers/_html_base.py 2026-06-26 10:26:58 UTC (rev 10372)
+++ trunk/docutils/docutils/writers/_html_base.py 2026-06-27 17:25:07 UTC (rev 10373)
@@ -580,20 +580,20 @@
if ids:
atts['id'] = ids[0]
for id in ids[1:]:
- # Add empty "span" elements for additional IDs. Note
- # that we cannot use empty "a" elements because there
- # may be targets inside of references, but nested "a"
- # elements aren't allowed in XHTML (even if they do
- # not all have a "href" attribute).
+ # Add empty "span" elements for additional IDs:
if empty or isinstance(node, (nodes.Sequential,
nodes.docinfo,
nodes.table)):
# Insert target right in front of element.
prefix.append('<span id="%s"></span>' % id)
+ if suffix.startswith('\n'):
+ prefix.append('\n')
else:
# Non-empty tag. Place the auxiliary <span> tag
# *inside* the element, as the first child.
- suffix += '<span id="%s"></span>' % id
+ suffix += f'<span id="{id}"></span>'
+ if suffix.startswith('\n'):
+ suffix += '\n'
attlist = sorted(atts.items())
parts = [tagname]
for name, value in attlist:
Modified: trunk/docutils/test/functional/expected/misc_rst_html4css1.html
===================================================================
--- trunk/docutils/test/functional/expected/misc_rst_html4css1.html 2026-06-26 10:26:58 UTC (rev 10372)
+++ trunk/docutils/test/functional/expected/misc_rst_html4css1.html 2026-06-27 17:25:07 UTC (rev 10373)
@@ -50,7 +50,8 @@
</div>
</div>
<div class="section" id="section-titles-with-inline-markup">
-<span id="references"></span><h1>Section titles with inline markup</h1>
+<span id="references"></span>
+<h1>Section titles with inline markup</h1>
<div class="section" id="emphasized-h2o-x-2-and-references">
<h2><em>emphasized</em>, H<sub>2</sub>O, <span class="formula"><i>x</i><sup>2</sup></span>, and <a class="reference internal" href="#references">references</a></h2>
</div>
Modified: trunk/docutils/test/functional/expected/misc_rst_html5.html
===================================================================
--- trunk/docutils/test/functional/expected/misc_rst_html5.html 2026-06-26 10:26:58 UTC (rev 10372)
+++ trunk/docutils/test/functional/expected/misc_rst_html5.html 2026-06-27 17:25:07 UTC (rev 10373)
@@ -97,7 +97,8 @@
</section>
</section>
<section id="section-titles-with-inline-markup">
-<span id="references"></span><h2><a class="toc-backref" href="#contents" role="doc-backlink">Section titles with inline markup</a><a class="self-link" title="link to this section" href="#references"></a></h2>
+<span id="references"></span>
+<h2><a class="toc-backref" href="#contents" role="doc-backlink">Section titles with inline markup</a><a class="self-link" title="link to this section" href="#references"></a></h2>
<section id="emphasized-h2o-x-2-and-references">
<h3><em>emphasized</em>, H<sub>2</sub>O, <math xmlns="http://www.w3.org/1998/Math/MathML">
<msup>
Modified: trunk/docutils/test/functional/expected/standalone_rst_html4css1.html
===================================================================
--- trunk/docutils/test/functional/expected/standalone_rst_html4css1.html 2026-06-26 10:26:58 UTC (rev 10372)
+++ trunk/docutils/test/functional/expected/standalone_rst_html4css1.html 2026-06-27 17:25:07 UTC (rev 10373)
@@ -534,7 +534,8 @@
citation.</p>
</div>
<div class="section" id="targets">
-<span id="another-target"></span><h2><a class="toc-backref" href="#toc-entry-19">2.13 Targets</a></h2>
+<span id="another-target"></span>
+<h2><a class="toc-backref" href="#toc-entry-19">2.13 Targets</a></h2>
<p id="example">This paragraph is pointed to by the explicit "example" target. A
reference can be found under <a class="reference internal" href="#inline-markup">Inline Markup</a>, above. <a class="reference internal" href="#inline-hyperlink-targets">Inline
hyperlink targets</a> are also possible.</p>
@@ -591,7 +592,9 @@
<img alt="../../../docs/user/rst/images/title.png" class="class1 class2" src="../../../docs/user/rst/images/title.png" style="width: 70%;" />
</a>
<p>Image with multiple IDs:</p>
-<span id="image-target-2"></span><span id="image-target-1"></span><img alt="../../../docs/user/rst/images/biohazard.png" id="image-target-3" src="../../../docs/user/rst/images/biohazard.png" />
+<span id="image-target-2"></span>
+<span id="image-target-1"></span>
+<img alt="../../../docs/user/rst/images/biohazard.png" id="image-target-3" src="../../../docs/user/rst/images/biohazard.png" />
<p>A centered image:</p>
<img alt="../../../docs/user/rst/images/biohazard.png" class="align-center" src="../../../docs/user/rst/images/biohazard.png" />
<p>A left-aligned image:</p>
@@ -745,7 +748,8 @@
<p>With the "widths" argument "auto" (or "class" value "colwidths-auto"),
column widths are determined by the backend (if supported by the
writer/backend).</p>
-<span id="target1"></span><table border="1" class="docutils" id="target2">
+<span id="target1"></span>
+<table border="1" class="docutils" id="target2">
<thead valign="bottom">
<tr><th class="head">A</th>
<th class="head">B</th>
Modified: trunk/docutils/test/functional/expected/standalone_rst_html5.html
===================================================================
--- trunk/docutils/test/functional/expected/standalone_rst_html5.html 2026-06-26 10:26:58 UTC (rev 10372)
+++ trunk/docutils/test/functional/expected/standalone_rst_html5.html 2026-06-27 17:25:07 UTC (rev 10373)
@@ -531,7 +531,8 @@
citation.</p>
</section>
<section id="targets">
-<span id="another-target"></span><h3><a class="toc-backref" href="#toc-entry-19" role="doc-backlink"><span class="sectnum">2.13 </span>Targets</a><a class="self-link" title="link to this section" href="#another-target"></a></h3>
+<span id="another-target"></span>
+<h3><a class="toc-backref" href="#toc-entry-19" role="doc-backlink"><span class="sectnum">2.13 </span>Targets</a><a class="self-link" title="link to this section" href="#another-target"></a></h3>
<p id="example">This paragraph is pointed to by the explicit "example" target. A
reference can be found under <a class="reference internal" href="#inline-markup">Inline Markup</a>, above. <a class="reference internal" href="#inline-hyperlink-targets">Inline
hyperlink targets</a> are also possible.</p>
@@ -588,7 +589,9 @@
<img alt="../../../docs/user/rst/images/title.png" class="class1 class2" src="../../../docs/user/rst/images/title.png" style="width: 70%;" />
</a>
<p>Image with multiple IDs:</p>
-<span id="image-target-2"></span><span id="image-target-1"></span><img alt="../../../docs/user/rst/images/biohazard.png" id="image-target-3" src="../../../docs/user/rst/images/biohazard.png" />
+<span id="image-target-2"></span>
+<span id="image-target-1"></span>
+<img alt="../../../docs/user/rst/images/biohazard.png" id="image-target-3" src="../../../docs/user/rst/images/biohazard.png" />
<p>A centered image:</p>
<img alt="../../../docs/user/rst/images/biohazard.png" class="align-center" src="../../../docs/user/rst/images/biohazard.png" />
<p>A left-aligned image:</p>
@@ -734,7 +737,8 @@
<p>With the "widths" argument "auto" (or "class" value "colwidths-auto"),
column widths are determined by the backend (if supported by the
writer/backend).</p>
-<span id="target1"></span><table id="target2">
+<span id="target1"></span>
+<table id="target2">
<thead>
<tr><th class="head"><p>A</p></th>
<th class="head"><p>B</p></th>
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|