From 509329893169d4f43274dd6c6d7ba2e2c5acb07e Mon Sep 17 00:00:00 2001 From: "J. Miguel Farto" Date: Sun, 6 Dec 2015 16:51:17 +0100 Subject: [PATCH] make live docs and html/rst uploads compatible with autoescape --- sagenb/notebook/docHTMLProcessor.py | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/sagenb/notebook/docHTMLProcessor.py b/sagenb/notebook/docHTMLProcessor.py index 6423f01d5..7b3ec93ae 100755 --- a/sagenb/notebook/docHTMLProcessor.py +++ b/sagenb/notebook/docHTMLProcessor.py @@ -97,6 +97,10 @@ }}} + +WARNING: + + Input strings must be unicode. """ ############################################################################# # Copyright (C) 2007 William Stein and Dorian Raimer @@ -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 @@ -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') @@ -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('<', '<') - p = p.replace('>', '>') - p = p.replace('&', '&') - p = p.replace(''', "'") # first occurrence of an output string # write /// denoting output if output_flag == False: @@ -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