(write, elem, qnames, namespaces, **kwargs)
| 912 | "track", "wbr"} |
| 913 | |
| 914 | def _serialize_html(write, elem, qnames, namespaces, **kwargs): |
| 915 | tag = elem.tag |
| 916 | text = elem.text |
| 917 | if tag is Comment: |
| 918 | write("<!--%s-->" % _escape_cdata(text)) |
| 919 | elif tag is ProcessingInstruction: |
| 920 | write("<?%s?>" % _escape_cdata(text)) |
| 921 | else: |
| 922 | tag = qnames[tag] |
| 923 | if tag is None: |
| 924 | if text: |
| 925 | write(_escape_cdata(text)) |
| 926 | for e in elem: |
| 927 | _serialize_html(write, e, qnames, None) |
| 928 | else: |
| 929 | write("<" + tag) |
| 930 | items = list(elem.items()) |
| 931 | if items or namespaces: |
| 932 | if namespaces: |
| 933 | for v, k in sorted(namespaces.items(), |
| 934 | key=lambda x: x[1]): # sort on prefix |
| 935 | if k: |
| 936 | k = ":" + k |
| 937 | write(" xmlns%s=\"%s\"" % ( |
| 938 | k, |
| 939 | _escape_attrib(v) |
| 940 | )) |
| 941 | for k, v in items: |
| 942 | if isinstance(k, QName): |
| 943 | k = k.text |
| 944 | if isinstance(v, QName): |
| 945 | v = qnames[v.text] |
| 946 | else: |
| 947 | v = _escape_attrib_html(v) |
| 948 | # FIXME: handle boolean attributes |
| 949 | write(" %s=\"%s\"" % (qnames[k], v)) |
| 950 | write(">") |
| 951 | ltag = tag.lower() |
| 952 | if text: |
| 953 | if ltag == "script" or ltag == "style": |
| 954 | write(text) |
| 955 | else: |
| 956 | write(_escape_cdata(text)) |
| 957 | for e in elem: |
| 958 | _serialize_html(write, e, qnames, None) |
| 959 | if ltag not in HTML_EMPTY: |
| 960 | write("</" + tag + ">") |
| 961 | if elem.tail: |
| 962 | write(_escape_cdata(elem.tail)) |
| 963 | |
| 964 | def _serialize_text(write, elem): |
| 965 | for part in elem.itertext(): |
nothing calls this directly
no test coverage detected
searching dependent graphs…