It's another mess --- I'm not very familiar with Python's string methods
--- but the code below seems to work.  I've included a few comments.

    def SPHINX_set_introspect_html(self, html, completing=False):
        if completing:
            self.__introspect_html = html
        else:

# I think the following check should be in all *_set_introspect_html(),
# because set_introspect_html('') is called in worksheet.py, apparently
# with every cell evaluation.

            if html == '':
                self.__introspect_html = html
                return
            html = html.replace('\\\\', '\\')

            from sage.misc.misc import SAGE_ROOT, tmp_dir

# [...snip...]
# I pause here because Sphinx "includes" load.js in the output as many
# times as set_introspect_html() has been called, which I daresay is
# a riddle.  Even if we discard the header, this could become inefficient.

            os.environ['SAGE_DOC_JSMATH'] = "True"

# [...snip...]
# It seems that Sphinx doesn't always use blockquotes, so I've
# added a few checks.  I'm sure this could be much simpler.

            html = new_html
            i = html.find('<div class="body">')
            html = html[i:]
            i = html.rfind('</blockquote>')
            if i == -1:
                i = html.rfind('<div class="sphinxsidebar">')
                if i == -1:
                    pass       # worst case
                else:
                    html = html[:i]
                    i = html.rfind('</div>')
                    html = html[:i]
                    i = html.rfind('</div>')
                    html = html[:i]
                    i = html.rfind('</div>')
                    html = html[:i]
            else:
                html = html[:i+13]
            html = html.replace('<pre>', '<pre class="literal-block">')
            html = '<div class="docstring">' + html + '</div>'
            self.__introspect_html = html


With a dedicated "doc" directory in DOT_SAGE and some help from Python's
hashlib module, we might be able to keep a persistent (yet disposable)
cache of documentation, along the lines of ccache.  It may be cheaper
for set_introspect_html() to apply a hash function to the incoming data
than to run Sphinx.  (Alternatively, we could pass a time stamp as
another argument.)  We could use the hash hex values themselves, plus
some human-readable identifiers, as file names.  But I'm just speculating.


Sincerely,
Pat LeSmithe

John H Palmieri wrote:
> On Mar 31, 11:10 pm, Pat LeSmithe <qed...@gmail.com> wrote:
>> After some manual inspection of Sphinx's cmdline.py, I think I've made
>> some [crude] progress (screenshot attached).  In cell.py, I replaced
>> Cell.set_introspect_html() with
> 
> This is cool.  I've modified it a bit: I've deleted some of the html
> and I've added some of the style sheet stuff to server/notebook/
> css.py.  I'll try to add a patch to the trac ticket later today.
> 
>> This has many problems:
>>
>> * It creates a new temporary directory for every non-completing
>> introspection.
> 
> Right, and I think this makes it a bit slower than the ideal.  I don't
> know if it's too slow to be usable.
> 
>> * It needs CSS class-fication, e.g., with class="introspection", to
>> avoid spontaneously restyling other page elements.
> 
> I think I've fixed this.
> 
>> * It doesn't touch completions.  Perhaps this is OK.
> 
> Well, typing
> 
>   sage.algebras.steenrod_algebra
> 
> doesn't even produce a docstring with my version of your patch.
> 
>> * ?? output has extra triple quotes.
> 
> Hmm.  I haven't looked into this.
> 
>> * It still doesn't get the math right, though I think it does link to
>> some jsMath code.
> 
> I've fixed this.
> 
>> * Search doesn't work.
>> * Links to the source and index are broken.  I tried, unsuccessfully, to
>> move the sidebar to the right (seehttp://sphinx.pocoo.org/theming.html).
>> * No cross-links.  Maybe doctreedir and freshenv are relevant here, too.
> 
> I've deleted all of the extra stuff: just show the docstring.
> 
> Here's a link to a new picture: (how do I add links to posts?)
> 
> <http://sage.math.washington.edu/home/palmieri/misc/sphinx.png>
> 
>   John
> 
> > 

--~--~---------~--~----~------------~-------~--~----~
To post to this group, send email to sage-devel@googlegroups.com
To unsubscribe from this group, send email to 
sage-devel-unsubscr...@googlegroups.com
For more options, visit this group at http://groups.google.com/group/sage-devel
URLs: http://www.sagemath.org
-~----------~----~----~----~------~----~------~--~---

Reply via email to