Skip to content
This repository has been archived by the owner on Jun 18, 2020. It is now read-only.

Commit

Permalink
With introspection and live documentation in the notebook, fix spurio…
Browse files Browse the repository at this point in the history
…us \(,\) and \[,\] pairs
  • Loading branch information
jhpalmieri committed Sep 17, 2012
1 parent dbabb90 commit 7aadeb3
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 7 deletions.
24 changes: 18 additions & 6 deletions sagenb/misc/sphinxify.py
Expand Up @@ -34,16 +34,29 @@ def is_sphinx_markup(docstring):
"""
Returns whether a string that contains Sphinx-style ReST markup.
This always returns True! For Sage docstrings, we always want to
assume that docstrings ReST markup; otherwise, text and symbols
(for example backslashes) in docstrings will be treated
inconsistently depending on whether the docstring is treated as
Sphinx markup.
INPUT:
- ``docstring`` - string to test for markup
OUTPUT:
- boolean
- boolean - always returns True
EXAMPLES::
sage: from sagenb.misc.sphinxify import is_sphinx_markup
sage: is_sphinx_markup('')
True
sage: is_sphinx_markup('.. note::')
True
"""
# this could be made much more clever
return ("`" in docstring or "::" in docstring)
return True


def sphinxify(docstring, format='html'):
Expand Down Expand Up @@ -91,9 +104,6 @@ def sphinxify(docstring, format='html'):
suffix = '.txt'
output_name = base_name + suffix

# This is needed for MathJax to work.
docstring = docstring.replace('\\\\', '\\')

filed = open(rst_name, 'w')
filed.write(docstring)
filed.close()
Expand Down Expand Up @@ -133,6 +143,8 @@ def sphinxify(docstring, format='html'):
output = re.sub("""src=['"](/?\.\.)*/?media/([^"']*)['"]""",
'src="/doc/static/reference/media/\\2"',
output)
# Remove spurious \(, \), \[, \].
output = output.replace('\\(', '').replace('\\)', '').replace('\\[', '').replace('\\]', '')
else:
print "BUG -- Sphinx error"
if format == 'html':
Expand Down
2 changes: 1 addition & 1 deletion sagenb/notebook/docHTMLProcessor.py
Expand Up @@ -153,7 +153,7 @@ def process_doc_html(self, doc_in):
self.feed(doc_in) #SGMLParser call
self.close() #SGMLParser call
self.hand_off_temp_pieces('to_doc_pieces')
return self.all_pieces
return self.all_pieces.replace('\\(', '').replace('\\)', '').replace('\\[', '').replace('\\]', '')


def hand_off_temp_pieces(self, piece_type):
Expand Down

0 comments on commit 7aadeb3

Please sign in to comment.