from nbformat.v4 import new_markdown_cell def get_rendered_contents(nb): cl = ["text_cell", "render"] rendered_cells = [cell.find_element_by_class_name("text_cell_render") for cell in nb.cells if all([c in cell.get_attribute("class") for c in cl])] return [x.get_attribute('innerHTML').strip() for x in rendered_cells if x is not None] def test_markdown_cell(prefill_notebook): nb = prefill_notebook([new_markdown_cell(md) for md in [ '# Foo', '**Bar**', '*Baz*', '```\nx = 1\n```', '```aaaa\nx = 1\n```', '```python\ns = "$"\nt = "$"\n```' ]]) assert get_rendered_contents(nb) == [ '

FooΒΆ

', '

Bar

', '

Baz

', '
x = 1
', '
x = 1
', '
' + 
        's = "$"\n' +
        't = "$"
' ] def test_markdown_headings(notebook): lst = list([1, 2, 3, 4, 5, 6, 2, 1]) for i in lst: notebook.add_markdown_cell() cell_text = notebook.browser.execute_script(f""" var cell = IPython.notebook.get_cell(1); cell.set_heading_level({i}); cell.get_text(); """) assert notebook.get_cell_contents(1) == "#" * i + " " notebook.delete_cell(1)