py2nb
py2nb copied to clipboard
Spyder IDE cell support
Just hacked this together for Spyder - shall I make a PR? Is this project still active?
Inside def convert_toplevel_docstring(tokens):
elif token.type == tokenize.COMMENT:
text = token.string
if text.startswith('#%%'):
#print("Spyder cell")
startline, startcol = token.start
# Starting column MUST be 0
if startcol == 0:
endline, endcol = token.end
lines = [line
for line in text.strip('"\' \n').split('\n')]
assert len(lines) == 1
text = '\n'.join(lines)
#text = text[3:]
text = text.replace("#%%", "")
text = text.lstrip()
fmt = '# <markdowncell>\n{0}\n# <codecell>'.format(text)
res = TokenInfo(type=tokenize.COMMENT,
start=(startline, startcol),
end=(endline, endcol),
string=fmt,
line='#')
yield res
# To next token
continue