Ejemplo n.º 1
0
    def generate(self):
        yield '<div class="notebook">'
        for cell in self.nb.cells:
            if cell.cell_type == 'code':
                div = Div()
                div.append_raw(highlight(cell.source, self.lexer, self.formatter))
                div.add_css_classes('cell', 'code-cell')
                yield div

        yield '</div>'
Ejemplo n.º 2
0
def make_fragment(obj):
    if isinstance(obj, h5py.Group):
        name = file_or_grp_name(obj)
        ct = make_list(item_for_group(name, obj))
    elif isinstance(obj, (str, Path)) and h5py.is_hdf5(obj):
        with h5py.File(obj, 'r') as f:
            return make_fragment(f)
    else:
        raise TypeError("Unknown object type: {!r}".format(obj))

    # Expand first level
    first_chkbx = ct.children.children[0].children.children[0] # Yuck
    first_chkbx.checked = True

    tv = Division(ct)
    tv.add_css_classes("h5glance-css-treeview")
    tv.id = next(treeview_ids)
    return tv
Ejemplo n.º 3
0
def h5obj_to_html(obj):
    treeview = make_fragment(obj)
    js_activate = JS_ACTIVATE_COPYLINKS_FRAG.replace("TREEVIEW-ID", treeview.id)

    div = Division(
        get_treeview_css(),
        treeview,
        Script(script=get_copylinks_js(js_activate)),
    )
    return str(div)
Ejemplo n.º 4
0
 def test_without_initial_content(self):
     div = Division()
     div.append("Test")
     assert_equal([b"<div>", b"Test", b"</div>"], list(iter(div)))
Ejemplo n.º 5
0
 def test_with_initial_content(self):
     div = Division("foo", "bar")
     div.append("baz")
     assert_equal("<div>foobarbaz</div>", str(div))