3 examples of 'jupyter notebook markdown new line' in Python

Every line of 'jupyter notebook markdown new line' code snippets is scanned for vulnerabilities by our powerful machine learning engine that combs millions of open source libraries, ensuring your Python code is secure.

All examples are scanned by Snyk Code

By copying the Snyk Code Snippets you agree to
10@cell_magic
11def markdown(self, line, cell):
12 from IPython.core.display import HTML
13
14 vars = line.split()
15
16 d = {}
17 for k, v in self.shell.user_ns.items():
18 if k in vars:
19 d[k] = v
20
21 return HTML("<p>{}</p>".format(markdown(cell.format(**d))))
10def gen_notebook(cells: List[Tuple[str, str]], tmp_dir: str, file_name: str,
11 docstring: str = None, header: str = None):
12 nb = nbf.v4.new_notebook()
13 if header:
14 nb['cells'].append(nbf.v4.new_markdown_cell(header))
15 if docstring:
16 nb['cells'].append(nbf.v4.new_code_cell(docstring))
17 for type, cell_content in cells:
18 if type == 'code':
19 nb_cell = to_notebook_code_cell(cell_content)
20 else:
21 nb_cell = to_notebook_comment_cell(cell_content)
22 nb['cells'].append(nb_cell)
23 notebook_path = join(tmp_dir, file_name)
24 nbf.write(nb, notebook_path)
25 return notebook_path
76def write_markdown(self, text):
77 if self.nb.cells[-1].cell_type != "markdown":
78 self.nb.cells.append(nbformat.from_dict({
79 "cell_type": "markdown",
80 "metadata": {},
81 "source": []
82 }))
83
84 self.nb.cells[-1].source.append(
85 text.replace("\n", "\n" + " " * self.indent)
86 )

Related snippets