Closed thatcher closed 3 years ago
I'm not sure that there is an easy fix here :-( The current code behind this is basically the same as writing this in a cell in the notebook:
In [5]: u"üä"
Out[5]: u'\xfc\xe4'
So, if the above inline code should return the string without quotes (and as a normal "readable" unicode instead of encoded ones) but in code blocks this should show quotes and u"..."
signs... this needs to switch the plain text formatter for unicode/str before/after each submitted code (or at least when switching from inline to block and reverse) :-/
from IPython.core.interactiveshell import InteractiveShell
shell = InteractiveShell.instance()
tp = shell.display_formatter.formatters[u'text/plain']
def pp(x,p,z):
p.text(x)
tp.type_printers[unicode] = pp
tp.type_printers[str] = pp
Not sure if there are any better alternatives...
Or the easier way: add a small wrapper in the engine code which does this for you:
engine would then need to setup p (or better a function with a unique and hidden name, which imports the right things and submits the final value to the ipython formatter...) in the engine setup and needs a configureable string which is used as the template, which should surround the inline code
So instead of submitting my_name
it's submitting _kpf(my_name)
to the kernel...
In a .pymd this is the mark up
renders as
My name is u'Chris'
instead of
My name is Chris