Ask Your Question

Is there a way to fix my html() lines?

asked 2015-09-15 09:24:06 -0500

Shai gravatar image

updated 2015-09-20 10:24:54 -0500

Recently, about 8 weeks of my work were gobbled up by the decision to make html() return a string of html rather than to display the html output.

I am using the html() function to produce html output on a teaching website through the SageCell like so:

html('Suppose we wanted to calculate $2+2=4$')

In combination with MathJaX this gives a very favourable output. I don't want to get into why it has to be html, but let's just assume I only want to display with html.

Then there is this

I have hundreds of uses of html() and they are all now showing deprecation warnings. I now need to use pretty_print(html()), apparrently. I won't give my opinion on the sense of this change, I just want to know how to properly fix it.

Is there a nice way to update my work? Is there a nice way of replacing all instances of html() with pretty_print(html())? I cannot do it manually, and search/replace seems to be ruled out by that close bracket.

Please forgive me if this is obvious. I'm an educator hacking my way through webdesign and I have never dealt with a large-scale deprecation like this.

edit retag flag offensive close merge delete


NOT obvious. Although there is something called 'regular expressions' that would allow you to pretty effectively replace all your instances, I do not think we should be expecting end users to have to learn regex to deal with a deprecation like this.

kcrisman gravatar imagekcrisman ( 2015-09-15 09:31:35 -0500 )edit

By the way, I'm surprised (but can confirm) that the cell server is using a beta. That's also not necessarily cool.

kcrisman gravatar imagekcrisman ( 2015-09-15 09:32:27 -0500 )edit

1 answer

Sort by » oldest newest most voted

answered 2015-09-15 10:05:56 -0500

Jaleks gravatar image

maybe something like this Python snippet below – used before the first time you try 'html()' – will do the trick for you; here it is working in a quick test...

    # if old_html ist not yet defined
    old_html == None
except NameError:
    # set it to the current html function
    old_html = html
    # and define a wrapper
    def html(*args):

# now try results
old_html('Suppose we wanted to calculate $2+2=4$')
html('Suppose we wanted to calculate $2+2=4$')
edit flag offensive delete link more


So maybe this would be defined and evaluated at the top of a Sage-cell-enabled web page?

kcrisman gravatar imagekcrisman ( 2015-09-15 10:21:22 -0500 )edit

If I paste it in: the output of html() will be without warning, is pretty printed and (hopefully) will be in future (?)

Jaleks gravatar imageJaleks ( 2015-09-15 10:46:40 -0500 )edit

Yes, one would hope this would work, I just am thinking out loud about how this would be implemented in embedded instances like the OP is talking about.

kcrisman gravatar imagekcrisman ( 2015-09-15 13:39:33 -0500 )edit

Thanks for the suggestions. My site is built through WordPress which puts everything into and then out of a MySQL database which strips out all of the "\n\r" line breaks in my php files making it impossible to have more than one line of formatted python injected into every cell instance. All I can now do is muddle around with some WordPress regex plugins and see what I can make happen.

Shai gravatar imageShai ( 2015-09-20 10:23:40 -0500 )edit

Oh, yeah, if you don't have control over your html that will be more challenging.

kcrisman gravatar imagekcrisman ( 2015-09-22 02:41:58 -0500 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower


Asked: 2015-09-15 09:24:06 -0500

Seen: 273 times

Last updated: Sep 20 '15