ipynb: format variations

This commit is contained in:
Jean-Francois Dockes 2021-10-10 09:45:37 +02:00
parent 687022d2ae
commit 8a98635c3a

View File

@ -35,18 +35,22 @@ class IPYNBextractor(RclBaseHandler):
text = open(fn, 'rb').read() text = open(fn, 'rb').read()
data = json.loads(text) data = json.loads(text)
mdtext = "" mdtext = ""
for cell in data["cells"]: if "worksheets" in data:
cells = data["worksheets"][0]["cells"]
else:
cells = data["cells"]
for cell in cells:
if cell["cell_type"] == "markdown": if cell["cell_type"] == "markdown":
mdtext += "\n" mdtext += "\n"
for line in cell["source"]: for line in cell["source"]:
mdtext += "# " + line mdtext += "# " + line + "\n"
mdtext += "\n"
elif cell["cell_type"] == "code": elif cell["cell_type"] == "code":
mdtext += "\n\n" mdtext += "\n\n"
for line in cell["source"]: key = "source" if "source" in cell else "input"
for line in cell[key]:
mdtext += line mdtext += line
mdtext += "\n" mdtext += "\n"
print("%s"%mdtext, file=sys.stderr) #print("%s"%mdtext, file=sys.stderr)
self.outputmimetype = 'text/plain' self.outputmimetype = 'text/plain'
return mdtext return mdtext