python - Include carriage return correctly in iPython notebooks when writing using json.dump -
i'm trying generate ipython notebooks json files python. i'm not sure how write carriage returns file in cells i've specified cell_type
markdown. i've tried double spaces, suggested here, , can markdown make new line specifying <br />
if include header specification markdown treats whole input header.
for instance:
import json # single markdown cell dictionary cell = { "cell_type" : "markdown", "metadata" : {'collapsed': false, 'name': 'test'}, "source" : ["## header line", "<br />", "second line, not header...hopefully"], } # create ipython notebook dictionary nbdict = { 'metadata': {}, \ 'nbformat': 4, 'nbformat_minor': 0, 'cells': [cell] } open('test.ipynb', 'w') outfile: json.dump(nbdict, outfile)
then if open ipython notebook test.ipynb
have following output:
header line second line, not header...hopefully
but it's in bold type, whole input being treated 1 line header.
how specify carriage returns properly, headers honoured single line, when i'm creating these notebooks?
markdown uses newlines separate lines, not html <br/>
tags. include newlines in source lines; use double newlines separate paragraph elements (including headers):
cell = { "cell_type": "markdown", "metadata": {'collapsed': false, 'name': 'test'}, "source": [ "## header line\n\n", "second line, not header...hopefully" ], }
Comments
Post a Comment