Discussion:
[Docutils-users] some single quotes in code blocks, wrapped as error in html ouput
Jeff Hinrichs - DM&T
2016-01-01 15:08:02 UTC
Permalink
rSt:

.. code:: python
'a' < 'b'
True
type(5)
<class 'int'>
type(5.0)
<class 'float'>

HTML: (rst2html) <body> <div class="document"> <pre class="code python literal-block"> <span class="operator">&gt;&gt;&gt;</span> <span class="literal
string">'a'</span> <span class="operator">&lt;</span> <span class="literal
string">'b'</span> <span class="name builtin pseudo">True</span> <span class="operator">&gt;&gt;&gt;</span> <span class="name
builtin">type</span><span class="punctuation">(</span><span class="literal
number integer">5</span><span class="punctuation">)</span>
<span class="operator">&lt;</span><span class="keyword">class</span> <span
class="error">'</span><span class="name class">int</span><span
class="literal string">'&gt;</span> <span class="operator">&gt;&gt;&gt;</span> <span class="name
builtin">type</span><span class="punctuation">(</span><span class="literal
number float">5.0</span><span class="punctuation">)</span>
<span class="operator">&lt;</span><span class="keyword">class</span> <span
class="error">'</span><span class="name class">float</span><span
class="literal string">'&gt;</span>
</pre>
</div>
</body>

rst2html.py --verbose class.rst class.html

$ rst2html.py --version
rst2html.py (Docutils 0.12 [release], Python 3.4.3, on linux)

Escaping in a code block does not work, just shows slash and then wraps
following char in an error span tag.
Help?
--
Best,

Jeff Hinrichs
402.218.1473
Guenter Milde
2016-01-01 19:43:59 UTC
Permalink
Subject: some single quotes in code blocks, wrapped as error in html ouput
They are actually *highlighted* as "error" by pygments.

The reason seems to be, that you set the language to "python" but the code
block contains an interactive Python session or a doctest.
Pygments uses the language name "pycon" in this case:

.. code:: pycon
'a' < 'b'
True
type(5)
<class 'int'>
type(5.0)
<class 'float'>
HTML: (rst2html)
works for me here.
Escaping in a code block does not work,
Yes. Escaping only works in "parsed literal", but then you don't have syntax
highlight.


Günter


------------------------------------------------------------------------------
Loading...