code: def _serialize_html(
      write: Callable[[str], None],
      elem: Element,
      format: Literal["html", "xhtml"],
  ) -> None:
      tag = elem.tag
      text = elem.text
      if tag is Comment:
          write("<!--%s-->" % _escape_cdata(text))
      elif tag is ProcessingInstruction:
          write("<?%s?>" % _escape_cdata(text))
      elif tag is None:
          if text:
              write(_escape_cdata(text))
          for e in elem:
              _serialize_html(write, e, format)
      else:
          namespace_uri = None
          if isinstance(tag, QName):
              # `QNAME` objects store their data as a string: `{uri}tag`
              if tag.text[:1] == "{":
                  namespace_uri, tag = tag.text[1:].split("}", 1)
              else:
                  raise ValueError("QName objects must define a tag.")
          write("<" + tag)
          items = elem.items()
          if items:
              items = sorted(items)  # lexical order
              for k, v in items:
                  if isinstance(k, QName):
                      # Assume a text only `QName`
                      k = k.text
                  if isinstance(v, QName):
                      # Assume a text only `QName`
                      v = v.text
                  else:
                      v = _escape_attrib_html(v)
                  if k == v and format == "html":
                      # handle boolean attributes
                      write(" %s" % v)
                  else:
                      write(' {}="{}"'.format(k, v))
          if namespace_uri:
              write(' xmlns="%s"' % (_escape_attrib(namespace_uri)))
          if format == "xhtml" and tag.lower() in HTML_EMPTY:
              write(" />")
          else:
              write(">")
              if text:
                  if tag.lower() in ["script", "style"]:
                      write(text)
                  else:
                      write(_escape_cdata(text))
              for e in elem:
                  _serialize_html(write, e, format)
              if tag.lower() not in HTML_EMPTY:
                  write("</" + tag + ">")
      if elem.tail:
          write(_escape_cdata(elem.tail))
  
file_path: markdown/markdown/serializers.py
imports: from __future__ import annotations
  from xml.etree.ElementTree import ProcessingInstruction
  from xml.etree.ElementTree import Comment, ElementTree, Element, QName, HTML_EMPTY
  import re
  from typing import Callable, Literal, NoReturn
label_desc: Use image node_id 5 for calling a global function with example usage: _serialize_html(write, elem, format) without return types