Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Doctests are interpreted by the HTML template #63

Closed
mikael-s opened this issue Aug 26, 2015 · 3 comments

Comments

Projects
None yet
3 participants
@mikael-s
Copy link

commented Aug 26, 2015

When producing the output in HTML mode, doctests are simply interpreted as if they were part of markdown syntax and are replaced by (three) blockquotes.

For instance if you have the following code in a test.py file:

def f():
    '''
    >>> f()
    2
    '''
    return 2

Launching pdoc on that file with pdoc --html test.py will produce a HTML file where the docstring is replaced by the following code:

<blockquote>
<blockquote>
<blockquote>
<p>f()
2</p>
</blockquote>
</blockquote>
</blockquote>

Therefore the >>> are removed and the line return is ignored which makes the doctests hardly readable.

@peterjc

This comment has been minimized.

Copy link

commented Sep 8, 2017

I would retitle this slightly, but can confirm that pdoc does not nicely render docstests in docstrings. Example:

from __future__ import print_function

def double(x):
   """Return double the input value.

   >>> double(5)
   10
   >>> double(1.25)
   2.5

   """
   return x * 2

if __name__ == "__main__":
    for v in [0.1, 3, 123]:
        print("Doubling %r gives %r" % (v, double(v)))

Then

$ pdoc --version
0.3.2
$ pdoc --html example.py 
$ open example.m.html

Gives:

...
  <section id="section-items">

    <h2 class="section-title" id="header-functions">Functions</h2>
      
  <div class="item">
    <div class="name def" id="example.double">
    <p>def <span class="ident">double</span>(</p><p>x)</p>
    </div>
    

    
  
    <div class="desc"><p>Return double the input value.</p>
<blockquote>
<blockquote>
<blockquote>
<p>double(5)
10
double(1.25)
2.5</p>
</blockquote>
</blockquote>
</blockquote></div>
  <div class="source_cont">
...

screenshot 2017-09-08 10 48 47

@peterjc

This comment has been minimized.

Copy link

commented Sep 8, 2017

This seems to be a limitation of the markdown rendering engine - which makes sense after all, >>> is not part of the Markdown language.

If pdoc supported reStructuredText as input, that does include support for >>> doctests - see #111.

@cortesi

This comment has been minimized.

Copy link
Member

commented Jun 3, 2018

Please see #153 for a unified discussion ticket about docstring flavors.

@cortesi cortesi closed this Jun 3, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.