Skip to content
This repository has been archived by the owner on Apr 26, 2021. It is now read-only.

inline code string values rendering as unicode python, eg u'some string' instead of #27

Closed
thatcher opened this issue May 22, 2015 · 2 comments

Comments

@thatcher
Copy link

In a .pymd this is the mark up

My name is `python my_name`

renders as

My name is u'Chris'

instead of

My name is Chris

@jankatins
Copy link
Owner

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...

@jankatins
Copy link
Owner

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...

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants