Skip to content
Snippets Groups Projects
Commit c4c66036 authored by Garen Torikian's avatar Garen Torikian
Browse files

Merge pull request #546 from moreati/rst-doctest

Added doctest blocks to reStructuredText (with tests)
parents bdb490bb c5e6585d
No related branches found
No related tags found
No related merge requests found
Loading
Loading
@@ -45,7 +45,8 @@ except:
import codecs
 
from docutils import nodes
from docutils.parsers.rst import roles
from docutils.parsers.rst import directives, roles
from docutils.parsers.rst.directives.body import CodeBlock
from docutils.core import publish_parts
from docutils.writers.html4css1 import Writer, HTMLTranslator
 
Loading
Loading
@@ -63,6 +64,18 @@ SETTINGS = {
'field_name_limit': 50,
}
 
class DoctestDirective(CodeBlock):
"""Render Sphinx 'doctest:: [group]' blocks as 'code:: python'
"""
def run(self):
"""Discard any doctest group argument, render contents as python code
"""
self.arguments = ['python']
return super(DoctestDirective, self).run()
class GitHubHTMLTranslator(HTMLTranslator):
# removes the <div class="document"> tag wrapped around docs
# see also: http://bit.ly/1exfq2h (warning! sourceforge link.)
Loading
Loading
@@ -153,6 +166,9 @@ def main():
 
roles.register_canonical_role('kbd', kbd)
 
# Render source code in Sphinx doctest blocks
directives.register_directive('doctest', DoctestDirective)
parts = publish_parts(text, writer=writer, settings_overrides=SETTINGS)
if 'html_body' in parts:
html = parts['html_body']
Loading
Loading
Loading
Loading
@@ -31,6 +31,19 @@ The UTF-8 quote character in this table used to cause python to go boom. Now doc
Tabular Data, 5
Made up ratings, 11
 
.. code::
A block of code
.. code:: python
python.code('hooray')
.. doctest:: ignored
>>> some_function()
'result'
============== ==========================================================
Travis http://travis-ci.org/tony/pullv
Docs http://pullv.rtfd.org
Loading
Loading
Loading
Loading
@@ -16,6 +16,16 @@
<li>Somé UTF-8°</li>
</ol>
<p>The UTF-8 quote character in this table used to cause python to go boom. Now docutils just silently ignores it.</p>
<pre>
A block of code
</pre>
<pre lang="python">
python.code('hooray')
</pre>
<pre lang="python">
&gt;&gt;&gt; some_function()
'result'
</pre>
<table>
 
 
Loading
Loading
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment