html.py 文件源码

python
阅读 30 收藏 0 点赞 0 评论 0

项目:sff 作者: nevarezs 项目源码 文件源码
def generate_document_from_row_list(title, header, row_list):
    """Create HTML5 document from a table.

    Args:
      title: Title of html document.
      row_list: Table with the data to generate the document.
    """
    doc, tag, text = Doc().tagtext()
    doc.asis("<!DOCTYPE html>")
    with tag("html"):
        with tag("head"):
            doc.asis("<meta charset=\"utf-8\">")
            with tag("title"):
                text(title)
        with tag("body"):
            with tag("h1"):
                text(title)
            if (header is not None):
                with tag("h3"):
                    text(header)
            with tag("table", border="1"):
                for r in row_list:
                    num_cols = len(r)
                    with tag("tr"):
                        for i in range(num_cols):
                            with tag("td"):
                                if r[i] is None:
                                    text("")
                                elif unicode(r[i]).encode(
                                    "unicode-escape").startswith("<img"):
                                    doc.asis(r[i])
                                else:
                                    text(r[i])
    return doc.getvalue()
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号