|
From: <mi...@us...> - 2021-03-20 23:47:00
|
Revision: 8637
http://sourceforge.net/p/docutils/code/8637
Author: milde
Date: 2021-03-20 23:46:52 +0000 (Sat, 20 Mar 2021)
Log Message:
-----------
Fixup for r8636: use <small> for line numbers.
Modified Paths:
--------------
trunk/docutils/HISTORY.txt
trunk/docutils/docutils/writers/html5_polyglot/__init__.py
trunk/docutils/test/functional/expected/standalone_rst_html5.html
Modified: trunk/docutils/HISTORY.txt
===================================================================
--- trunk/docutils/HISTORY.txt 2021-03-19 00:23:33 UTC (rev 8636)
+++ trunk/docutils/HISTORY.txt 2021-03-20 23:46:52 UTC (rev 8637)
@@ -110,15 +110,17 @@
__ https://developer.mozilla.org/en-US/docs/Web/HTML/Viewport_meta_tag
- - Add code line numbers as "data-*" arguments.
- This way, they may be skipped when copying text from code blocks
- (see minimal.css). Solves feature request #32.
+ - Use <small> for code line numbers and also add them as "data-*" arguments.
* docutils/writers/html5_polyglot/minimal.css
- Move non-essential styling to ``plain.css``.
- Support "captionbelow" class value for tables.
Small fixes and tweaks.
+
+ - Support "captionbelow" class value for tables.
+
+ - Display code line numbers as pseudo-elements which are skipped
+ when copying text from code blocks. Solves feature request #32.
* docutils/writers/html5_polyglot/plain.css
Modified: trunk/docutils/docutils/writers/html5_polyglot/__init__.py
===================================================================
--- trunk/docutils/docutils/writers/html5_polyglot/__init__.py 2021-03-19 00:23:33 UTC (rev 8636)
+++ trunk/docutils/docutils/writers/html5_polyglot/__init__.py 2021-03-20 23:46:52 UTC (rev 8637)
@@ -320,19 +320,22 @@
if len(tags):
node.html5tagname = tags[0]
classes.remove(tags[0])
- else:
- node.html5tagname = 'span'
- if (classes == ['ln'] and isinstance(node.parent, nodes.literal_block)
+ elif (classes == ['ln'] and isinstance(node.parent, nodes.literal_block)
and 'code' in node.parent.get('classes')):
if self.body[-1] == '<code>':
- self.body[-1] = '<code data-lineno="%s">'%node.astext()
+ del(self.body[-1])
else:
- self.body.append('</code><code data-lineno="%s">'
- % node.astext())
+ self.body.append('</code>')
+ node.html5tagname = 'small'
+ else:
+ node.html5tagname = 'span'
self.body.append(self.starttag(node, node.html5tagname, ''))
def depart_inline(self, node):
self.body.append('</%s>' % node.html5tagname)
+ if (node.html5tagname == 'small' and node.get('classes') == ['ln']
+ and isinstance(node.parent, nodes.literal_block)):
+ self.body.append('<code data-lineno="%s">' % node.astext())
del(node.html5tagname)
# place inside HTML5 <figcaption> element (together with caption)
Modified: trunk/docutils/test/functional/expected/standalone_rst_html5.html
===================================================================
--- trunk/docutils/test/functional/expected/standalone_rst_html5.html 2021-03-19 00:23:33 UTC (rev 8636)
+++ trunk/docutils/test/functional/expected/standalone_rst_html5.html 2021-03-20 23:46:52 UTC (rev 8637)
@@ -1005,9 +1005,9 @@
<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"><code data-lineno=" 8 "><span class="ln"> 8 </span># print integers from 0 to 9:
-</code><code data-lineno=" 9 "><span class="ln"> 9 </span>for i in range(10):
-</code><code data-lineno="10 "><span class="ln">10 </span> print i</code></pre>
+<pre class="code python literal-block"><small class="ln"> 8 </small><code data-lineno=" 8 "># print integers from 0 to 9:
+</code><small class="ln"> 9 </small><code data-lineno=" 9 ">for i in range(10):
+</code><small class="ln">10 </small><code data-lineno="10 "> 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
@@ -1016,8 +1016,8 @@
<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"><code data-lineno="1 "><span class="ln">1 </span>.. header:: Document header
-</code><code data-lineno="2 "><span class="ln">2 </span>.. footer:: Document footer</code></pre>
+<pre class="code rst literal-block"><small class="ln">1 </small><code data-lineno="1 ">.. header:: Document header
+</code><small class="ln">2 </small><code data-lineno="2 ">.. footer:: Document footer</code></pre>
</section>
<section id="meta">
<h4><a class="toc-backref" href="#toc-entry-63"><span class="sectnum">2.14.11</span> Meta</a></h4>
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|