ASKSAGE: Sage Q&A Forum - Individual question feedhttp://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Tue, 22 Sep 2015 02:41:58 -0500Is there a way to fix my html() lines?http://ask.sagemath.org/question/29450/is-there-a-way-to-fix-my-html-lines/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 http://trac.sagemath.org/ticket/18292
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.Tue, 15 Sep 2015 09:24:06 -0500http://ask.sagemath.org/question/29450/is-there-a-way-to-fix-my-html-lines/Comment by kcrisman for <p>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.</p>
<p>I am using the html() function to produce html output on a teaching website through the SageCell like so:</p>
<pre><code>html('Suppose we wanted to calculate $2+2=4$')
</code></pre>
<p>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.</p>
<p>Then there is this <a href="http://trac.sagemath.org/ticket/18292">http://trac.sagemath.org/ticket/18292</a></p>
<p>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.</p>
<p>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.</p>
<p>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.</p>
http://ask.sagemath.org/question/29450/is-there-a-way-to-fix-my-html-lines/?comment=29454#post-id-29454By the way, I'm surprised (but can confirm) that the cell server is using a beta. That's also not necessarily cool.Tue, 15 Sep 2015 09:32:27 -0500http://ask.sagemath.org/question/29450/is-there-a-way-to-fix-my-html-lines/?comment=29454#post-id-29454Comment by kcrisman for <p>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.</p>
<p>I am using the html() function to produce html output on a teaching website through the SageCell like so:</p>
<pre><code>html('Suppose we wanted to calculate $2+2=4$')
</code></pre>
<p>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.</p>
<p>Then there is this <a href="http://trac.sagemath.org/ticket/18292">http://trac.sagemath.org/ticket/18292</a></p>
<p>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.</p>
<p>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.</p>
<p>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.</p>
http://ask.sagemath.org/question/29450/is-there-a-way-to-fix-my-html-lines/?comment=29453#post-id-29453NOT 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.Tue, 15 Sep 2015 09:31:35 -0500http://ask.sagemath.org/question/29450/is-there-a-way-to-fix-my-html-lines/?comment=29453#post-id-29453Answer by Jaleks for <p>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.</p>
<p>I am using the html() function to produce html output on a teaching website through the SageCell like so:</p>
<pre><code>html('Suppose we wanted to calculate $2+2=4$')
</code></pre>
<p>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.</p>
<p>Then there is this <a href="http://trac.sagemath.org/ticket/18292">http://trac.sagemath.org/ticket/18292</a></p>
<p>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.</p>
<p>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.</p>
<p>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.</p>
http://ask.sagemath.org/question/29450/is-there-a-way-to-fix-my-html-lines/?answer=29456#post-id-29456 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...
try:
# 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):
pretty_print(old_html(*args))
# now try results
old_html('Suppose we wanted to calculate $2+2=4$')
html('Suppose we wanted to calculate $2+2=4$')
Tue, 15 Sep 2015 10:05:56 -0500http://ask.sagemath.org/question/29450/is-there-a-way-to-fix-my-html-lines/?answer=29456#post-id-29456Comment by kcrisman for <p>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...</p>
<pre><code>try:
# 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):
pretty_print(old_html(*args))
# now try results
old_html('Suppose we wanted to calculate $2+2=4$')
html('Suppose we wanted to calculate $2+2=4$')
</code></pre>
http://ask.sagemath.org/question/29450/is-there-a-way-to-fix-my-html-lines/?comment=29529#post-id-29529Oh, yeah, if you don't have control over your html that will be more challenging.Tue, 22 Sep 2015 02:41:58 -0500http://ask.sagemath.org/question/29450/is-there-a-way-to-fix-my-html-lines/?comment=29529#post-id-29529Comment by Shai for <p>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...</p>
<pre><code>try:
# 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):
pretty_print(old_html(*args))
# now try results
old_html('Suppose we wanted to calculate $2+2=4$')
html('Suppose we wanted to calculate $2+2=4$')
</code></pre>
http://ask.sagemath.org/question/29450/is-there-a-way-to-fix-my-html-lines/?comment=29513#post-id-29513Thanks 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.Sun, 20 Sep 2015 10:23:40 -0500http://ask.sagemath.org/question/29450/is-there-a-way-to-fix-my-html-lines/?comment=29513#post-id-29513Comment by kcrisman for <p>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...</p>
<pre><code>try:
# 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):
pretty_print(old_html(*args))
# now try results
old_html('Suppose we wanted to calculate $2+2=4$')
html('Suppose we wanted to calculate $2+2=4$')
</code></pre>
http://ask.sagemath.org/question/29450/is-there-a-way-to-fix-my-html-lines/?comment=29461#post-id-29461Yes, 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.Tue, 15 Sep 2015 13:39:33 -0500http://ask.sagemath.org/question/29450/is-there-a-way-to-fix-my-html-lines/?comment=29461#post-id-29461Comment by Jaleks for <p>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...</p>
<pre><code>try:
# 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):
pretty_print(old_html(*args))
# now try results
old_html('Suppose we wanted to calculate $2+2=4$')
html('Suppose we wanted to calculate $2+2=4$')
</code></pre>
http://ask.sagemath.org/question/29450/is-there-a-way-to-fix-my-html-lines/?comment=29458#post-id-29458If I paste it in: https://sagecell.sagemath.org/ the output of html() will be without warning, is pretty printed and (hopefully) will be in future (?)Tue, 15 Sep 2015 10:46:40 -0500http://ask.sagemath.org/question/29450/is-there-a-way-to-fix-my-html-lines/?comment=29458#post-id-29458Comment by kcrisman for <p>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...</p>
<pre><code>try:
# 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):
pretty_print(old_html(*args))
# now try results
old_html('Suppose we wanted to calculate $2+2=4$')
html('Suppose we wanted to calculate $2+2=4$')
</code></pre>
http://ask.sagemath.org/question/29450/is-there-a-way-to-fix-my-html-lines/?comment=29457#post-id-29457So maybe this would be defined and evaluated at the top of a Sage-cell-enabled web page?Tue, 15 Sep 2015 10:21:22 -0500http://ask.sagemath.org/question/29450/is-there-a-way-to-fix-my-html-lines/?comment=29457#post-id-29457