def render_html(self, pretty=True, static_output=False, header_block=None, footer_block=None, pdf_page_size="A4"): """Returns html output of the block :param pretty: Toggles pretty printing of the resulting HTML. Not applicable for non-HTML output. :return html-code of the block """ # Render the contents html = root("html", doctype="html") head = append_to(html, "head") head = append_to(head, "meta", charset='utf-8') body = append_to(html, "body") # Make sure that the main style sheet is always included resource_deps = DependencyTracker(default_css_main) if header_block is not None: header_block._write_block(body, Cfg(), id_generator(), resource_deps=resource_deps, static_output=static_output) self._write_block(body, Cfg(), id_generator(), resource_deps=resource_deps, static_output=static_output) if footer_block is not None: footer_block._write_block(body, Cfg(), id_generator(), resource_deps=resource_deps, static_output=static_output) script_inflate.write(head) script_block_core.write(head) if static_output: # Add the load wait poller if there are any JS resources js_elem(body, "var loadWaitPoller=runWaitPoller();") # Write out resources for res in resource_deps: res.write(head) # Render the whole document (the parent of the html tag) content = render(html.parent, pretty=pretty) return content
def render_html(self, pretty=True, static_output=False, header_block=None, footer_block=None): """Returns html output of the block :param pretty: Toggles pretty printing of the resulting HTML. Not applicable for non-HTML output. :param static_output: Passed down to _write_block. Will render static version of blocks which support this. :param header_block: If not None, header is inlined into a HTML body as table. :param footer_block: If not None, header is inlined into a HTML body as table. :return html-code of the block """ # Render the contents html = root("html", doctype="html") head = append_to(html, "head") append_to(head, "meta", charset='utf-8') body = append_to(html, "body") # Make sure that the main style sheet is always included resource_deps = DependencyTracker(default_css_main) # If header or footer are passed into this function, inline them in the following structure: # # <body> # <table> # <thead><tr><td>Header html</td></tr></thead> # <tfoot><tr><td>Footer html</td></tr></tfoot> # <tbody><tr><td>Body html</td></tr></tbody> # </table> # </body> if header_block is not None or footer_block is not None: content_table = append_to(body, "table") if header_block is not None: header_thead = append_to(content_table, "thead") header_tr = append_to(header_thead, "tr") header_td = append_to(header_tr, "th") header_block._write_block(header_td, Cfg(), id_generator(), resource_deps=resource_deps, static_output=static_output) if footer_block is not None: footer_tfoot = append_to(content_table, "tfoot", id='footer') footer_tr = append_to(footer_tfoot, "tr") footer_td = append_to(footer_tr, "td") footer_block._write_block(footer_td, Cfg(), id_generator(), resource_deps=resource_deps, static_output=static_output) body_tbody = append_to(content_table, "tbody") body_tr = append_to(body_tbody, "tr") body_td = append_to(body_tr, "td") self._write_block(body_td, Cfg(), id_generator(), resource_deps=resource_deps, static_output=static_output) else: self._write_block(body, Cfg(), id_generator(), resource_deps=resource_deps, static_output=static_output) script_inflate.write(head) script_block_core.write(head) if static_output: # Add the load wait poller if there are any JS resources js_elem(body, "var loadWaitPoller=runWaitPoller();") # Write out resources for res in resource_deps: res.write(head) # Render the whole document (the parent of the html tag) content = render(html.parent, pretty=pretty) return content