Beispiel #1
0
 def test_title(self):
     doc = Document(title="Test Title")
     assert_equal("Test Title", doc.title)
     assert_equal("Test Title", doc.root.head.title.title)
     doc.title = "New Title"
     assert_equal("New Title", doc.title)
     assert_equal("New Title", doc.root.head.title.title)
Beispiel #2
0
 def test_scripts(self):
     head = _TestingHead()
     doc = Document()
     doc.root.head = head
     doc.add_script("script.js")
     doc.add_scripts("script1.js", "script2.js")
     assert_equal(["script.js", "script1.js", "script2.js"], head.scripts)
Beispiel #3
0
 def test_title(self):
     doc = Document(title="Test Title")
     assert_equal("Test Title", doc.title)
     assert_equal("Test Title", doc.root.head.title.title)
     doc.title = "New Title"
     assert_equal("New Title", doc.title)
     assert_equal("New Title", doc.root.head.title.title)
Beispiel #4
0
 def test_append(self):
     doc = Document()
     old_child_count = len(doc.root.head)
     doc.append_head("Test Head")
     assert_equal(old_child_count + 1, len(doc.root.head))
     doc.append_body("Test Body")
     assert_equal(1, len(doc.root.body))
Beispiel #5
0
 def test_stylesheets(self):
     head = _TestingHead()
     doc = Document()
     doc.root.head = head
     doc.add_stylesheet("style.css")
     doc.add_stylesheets("style1.css", "style2.css")
     assert_equal(["style.css", "style1.css", "style2.css"],
                  head.stylesheets)
Beispiel #6
0
 def test_append(self):
     head = _TestingHead()
     doc = Document()
     doc.root.head = head
     doc.append_head("Test Head")
     assert_equal(1, len(head))
     doc.append_body("Test Body")
     assert_equal(1, len(doc.root.body))
Beispiel #7
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
Beispiel #8
0
 def test_scripts(self):
     head = _TestingHead()
     doc = Document()
     doc.root.head = head
     doc.add_script("script.js")
     doc.add_scripts("script1.js", "script2.js")
     assert_equal(["script.js", "script1.js", "script2.js"], head.scripts)
Beispiel #9
0
 def test_append(self):
     doc = Document()
     old_child_count = len(doc.root.head)
     doc.append_head("Test Head")
     assert_equal(old_child_count + 1, len(doc.root.head))
     doc.append_body("Test Body")
     assert_equal(1, len(doc.root.body))
Beispiel #10
0
 def test_append(self):
     head = _TestingHead()
     doc = Document()
     doc.root.head = head
     doc.append_head("Test Head")
     assert_equal(1, len(head))
     doc.append_body("Test Body")
     assert_equal(1, len(doc.root.body))
Beispiel #11
0
 def test_stylesheets(self):
     head = _TestingHead()
     doc = Document()
     doc.root.head = head
     doc.add_stylesheet("style.css")
     doc.add_stylesheets("style1.css", "style2.css")
     assert_equal(["style.css", "style1.css", "style2.css"],
                  head.stylesheets)
Beispiel #12
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)
Beispiel #13
0
 def test_default_title(self):
     doc = Document()
     assert_equal("", doc.title)
     assert_equal("", doc.root.head.title.title)
Beispiel #14
0
 def test_language(self):
     doc = Document(language="de")
     assert_equal("de", doc.root.get_attribute("lang"))
     assert_equal("de", doc.root.get_attribute("xml:lang"))
Beispiel #15
0
 def test_default_language(self):
     doc = Document()
     assert_equal("en", doc.root.get_attribute("lang"))
     assert_equal("en", doc.root.get_attribute("xml:lang"))
Beispiel #16
0
 def test_generate(self):
     doc = Document()
     doc.root = cast(HTMLRoot, Element("html"))
     assert_equal([b"<!DOCTYPE html>", b"<html>", b"</html>"],
                  list(iter(doc)))
Beispiel #17
0
 def test_generate(self):
     doc = Document()
     doc.root = cast(HTMLRoot, Element("html"))
     assert_equal([b"<!DOCTYPE html>", b"<html>", b"</html>"],
                  list(iter(doc)))