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

Commit

Permalink
make live docs and html/rst uploads compatible with autoescape
Browse files Browse the repository at this point in the history
  • Loading branch information
migeruhito committed Dec 6, 2015
1 parent 3785eb0 commit 5093298
Showing 1 changed file with 15 additions and 8 deletions.
23 changes: 15 additions & 8 deletions sagenb/notebook/docHTMLProcessor.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,10 @@
}}}
<BLANKLINE>
<BLANKLINE>
WARNING:
Input strings must be unicode.
"""
#############################################################################
# Copyright (C) 2007 William Stein <wstein@gmail.com> and Dorian Raimer
Expand All @@ -105,11 +109,15 @@
# The full text of the GPL is available at:
# http://www.gnu.org/licenses/
#############################################################################
from __future__ import unicode_literals

from sgmllib import SGMLParser
from urllib import splittag
from htmlentitydefs import entitydefs

from flask import Markup
from sagenb.misc.misc import unicode_str


class genericHTMLProcessor(SGMLParser):
r"""
This class gathers the methods that are common to both classes
Expand Down Expand Up @@ -150,6 +158,11 @@ def process_doc_html(self, doc_in):
# self.feed() is a SGMLParser method and starts everything
# off; Most of the functions here are extensions to
# SGMLParser, and may never actually be visibly called here.

# This module works with unicode literals. In case that input data is
# ascii, exceptions may occur. So, input data must be converted to
# unicode if it were not.
doc_in = unicode_str(doc_in)
self.feed(doc_in) #SGMLParser call
self.close() #SGMLParser call
self.hand_off_temp_pieces('to_doc_pieces')
Expand Down Expand Up @@ -375,12 +388,6 @@ def process_cell_input_output(self, cell_piece):
elif p[:4] == '... ':
piece += p[4:] + '\n'
else:
# in an output string. replace escaped html
# strings so they don't get converted twice.
p = p.replace('&lt;', '<')
p = p.replace('&gt;', '>')
p = p.replace('&amp;', '&')
p = p.replace('&#39;', "'")
# first occurrence of an output string
# write /// denoting output
if output_flag == False:
Expand All @@ -392,7 +399,7 @@ def process_cell_input_output(self, cell_piece):
else:
piece += p
piece += '\n}}}\n\n'
return piece
return Markup(piece).unescape()

##############################################
## General tag handlers
Expand Down

0 comments on commit 5093298

Please sign in to comment.