code: def webify(v: Any, preserve_newlines: bool = True) -> str:
      
      nl = "<br>" if preserve_newlines else " "
      if v is None:
          return ""
      if not isinstance(v, str):
          v = str(v)
      # noinspection PyDeprecation
      return cgi.escape(v).replace("\n", nl).replace("\\n", nl)
docs: Converts a value into an HTML-safe ``str`` (formerly, in Python 2:
      ``unicode``).
  
      Converts value ``v`` to a string; escapes it to be safe in HTML
      format (escaping ampersands, replacing newlines with ``<br>``, etc.).
      Returns ``""`` for blank input.