Пример #1
0
 def test_type(self):
     script = Script()
     script.type = "application/json"
     assert_equal(
         [b'<script type="application/json">', b"</script>"],
         list(iter(script)),
     )
Пример #2
0
def make_document(obj):
    d = Document()
    d.append_head(get_treeview_css())
    d.append_head(Script(script=get_copylinks_js(JS_ACTIVATE_COPYLINKS_DOC)))
    d.title = "{} - H5Glance".format(file_or_grp_name(obj))
    d.append_body(make_fragment(obj))
    return d
Пример #3
0
def dump(nb, fp, nb_name):
    doc = Document(title=nb_name)
    langinfo = nb.metadata.get('language_info', {})
    lexer_name = langinfo.get('pygments_lexer', langinfo.get('name', None))
    lexer = _get_pygments_lexer(lexer_name)
    formatter = HtmlFormatter()
    pygments_styles = Style(formatter.get_style_defs())
    doc.append_head(pygments_styles)
    metadata_et = Script(script=json.dumps(nb.metadata))
    metadata_et.id = "nb_metadata"
    metadata_et.set_attribute('type', 'application/json')
    doc.append_head(metadata_et)
    doc.append_body(NotebookElement(nb, lexer, formatter))

    for fragment in doc:
        #print(repr(fragment))
        fp.write(fragment)
Пример #4
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)
Пример #5
0
 def test_type(self):
     script = Script()
     script.type = "application/json"
     assert_equal([b'<script type="application/json">', b'</script>'],
                  list(iter(script)))
Пример #6
0
 def test_type_default(self):
     script = Script()
     assert_equal("text/javascript", script.type)
Пример #7
0
 def test_script(self):
     script = Script(script='alert("foo");')
     assert_is_none(script.url)
     assert_equal('alert("foo");', script.script)
     assert_equal([b"<script>", b'alert("foo");', b"</script>"],
                  list(iter(script)))
Пример #8
0
 def test_url(self):
     script = Script(url="script.js")
     assert_equal("script.js", script.url)
     assert_is_none(script.script)
     assert_equal([b'<script src="script.js">', b"</script>"],
                  list(iter(script)))