class_docstr: A parser which converts Markdown to HTML.
  
  Attributes:
      Markdown.tab_length (int): The number of spaces which correspond to a single tab. Default: `4`.
      Markdown.ESCAPED_CHARS (list[str]): List of characters which get the backslash escape treatment.
      Markdown.block_level_elements (list[str]): List of HTML tags which get treated as block-level elements.
          See [`markdown.util.BLOCK_LEVEL_ELEMENTS`][] for the full list of elements.
      Markdown.registeredExtensions (list[Extension]): List of extensions which have called
          [`registerExtension`][markdown.Markdown.registerExtension] during setup.
      Markdown.doc_tag (str): Element used to wrap document. Default: `div`.
      Markdown.stripTopLevelTags (bool): Indicates whether the `doc_tag` should be removed. Default: 'True'.
      Markdown.references (dict[str, tuple[str, str]]): A mapping of link references found in a parsed document
           where the key is the reference name and the value is a tuple of the URL and title.
      Markdown.htmlStash (util.HtmlStash): The instance of the `HtmlStash` used by an instance of this class.
      Markdown.output_formats (dict[str, Callable[xml.etree.ElementTree.Element]]): A mapping of known output
           formats by name and their respective serializers. Each serializer must be a callable which accepts an
          [`Element`][xml.etree.ElementTree.Element] and returns a `str`.
      Markdown.output_format (str): The output format set by
          [`set_output_format`][markdown.Markdown.set_output_format].
      Markdown.serializer (Callable[xml.etree.ElementTree.Element]): The serializer set by
          [`set_output_format`][markdown.Markdown.set_output_format].
      Markdown.preprocessors (util.Registry): A collection of [`preprocessors`][markdown.preprocessors].
      Markdown.parser (blockparser.BlockParser): A collection of [`blockprocessors`][markdown.blockprocessors].
      Markdown.inlinePatterns (util.Registry): A collection of [`inlinepatterns`][markdown.inlinepatterns].
      Markdown.treeprocessors (util.Registry): A collection of [`treeprocessors`][markdown.treeprocessors].
      Markdown.postprocessors (util.Registry): A collection of [`postprocessors`][markdown.postprocessors].
class_docstr_tok: ["A","parser","which","converts","Markdown","to","HTML",".","Attributes",":","Markdown.tab_length","(","int",")",":","The","number","of","spaces","which","correspond","to","a","single","tab",".","Default",":","`","4","`",".","Markdown.ESCAPED_CHARS","(","list","[","str","]",")",":","List","of","characters","which","get","the","backslash","escape","treatment",".","Markdown.block_level_elements","(","list","[","str","]",")",":","List","of","HTML","tags","which","get","treated","as","block-level","elements",".","See","[","`","markdown.util.BLOCK_LEVEL_ELEMENTS","`","]","[","]","for","the","full","list","of","elements",".","Markdown.registeredExtensions","(","list","[","Extension","]",")",":","List","of","extensions","which","have","called","[","`","registerExtension","`","]","[","markdown.Markdown.registerExtension","]","during","setup",".","Markdown.doc_tag","(","str",")",":","Element","used","to","wrap","document",".","Default",":","`","div","`",".","Markdown.stripTopLevelTags","(","bool",")",":","Indicates","whether","the","`","doc_tag","`","should","be","removed",".","Default",":","'True","'",".","Markdown.references","(","dict","[","str",",","tuple","[","str",",","str","]","]",")",":","A","mapping","of","link","references","found","in","a","parsed","document","where","the","key","is","the","reference","name","and","the","value","is","a","tuple","of","the","URL","and","title",".","Markdown.htmlStash","(","util.HtmlStash",")",":","The","instance","of","the","`","HtmlStash","`","used","by","an","instance","of","this","class",".","Markdown.output_formats","(","dict","[","str",",","Callable","[","xml.etree.ElementTree.Element","]","]",")",":","A","mapping","of","known","output","formats","by","name","and","their","respective","serializers",".","Each","serializer","must","be","a","callable","which","accepts","an","[","`","Element","`","]","[","xml.etree.ElementTree.Element","]","and","returns","a","`","str","`",".","Markdown.output_format","(","str",")",":","The","output","format","set","by","[","`","set_output_format","`","]","[","markdown.Markdown.set_output_format","]",".","Markdown.serializer","(","Callable","[","xml.etree.ElementTree.Element","]",")",":","The","serializer","set","by","[","`","set_output_format","`","]","[","markdown.Markdown.set_output_format","]",".","Markdown.preprocessors","(","util.Registry",")",":","A","collection","of","[","`","preprocessors","`","]","[","markdown.preprocessors","]",".","Markdown.parser","(","blockparser.BlockParser",")",":","A","collection","of","[","`","blockprocessors","`","]","[","markdown.blockprocessors","]",".","Markdown.inlinePatterns","(","util.Registry",")",":","A","collection","of","[","`","inlinepatterns","`","]","[","markdown.inlinepatterns","]",".","Markdown.treeprocessors","(","util.Registry",")",":","A","collection","of","[","`","treeprocessors","`","]","[","markdown.treeprocessors","]",".","Markdown.postprocessors","(","util.Registry",")",":","A","collection","of","[","`","postprocessors","`","]","[","markdown.postprocessors","]","."]
docstr: Convert a Markdown string to a string in the specified output format.
  
  Arguments:
      source: Markdown formatted text as Unicode or ASCII string.
  
  Returns:
      A string in the specified output format.
  
  Markdown parsing takes place in five steps:
  
  1. A bunch of [`preprocessors`][markdown.preprocessors] munge the input text.
  2. A [`BlockParser`][markdown.blockparser.BlockParser] parses the high-level structural elements of the
     pre-processed text into an [`ElementTree`][xml.etree.ElementTree.ElementTree] object.
  3. A bunch of [`treeprocessors`][markdown.treeprocessors] are run against the
     [`ElementTree`][xml.etree.ElementTree.ElementTree] object. One such `treeprocessor`
     ([`markdown.treeprocessors.InlineProcessor`][]) runs [`inlinepatterns`][markdown.inlinepatterns]
     against the [`ElementTree`][xml.etree.ElementTree.ElementTree] object, parsing inline markup.
  4. Some [`postprocessors`][markdown.postprocessors] are run against the text after the
     [`ElementTree`][xml.etree.ElementTree.ElementTree] object has been serialized into text.
  5. The output is returned as a string.
docstr_tok: ["Convert","a","Markdown","string","to","a","string","in","the","specified","output","format",".","Arguments",":","source",":","Markdown","formatted","text","as","Unicode","or","ASCII","string",".","Returns",":","A","string","in","the","specified","output","format",".","Markdown","parsing","takes","place","in","five","steps",":","1",".","A","bunch","of","[","`","preprocessors","`","]","[","markdown.preprocessors","]","munge","the","input","text",".","2",".","A","[","`","BlockParser","`","]","[","markdown.blockparser.BlockParser","]","parses","the","high-level","structural","elements","of","the","pre-processed","text","into","an","[","`","ElementTree","`","]","[","xml.etree.ElementTree.ElementTree","]","object",".","3",".","A","bunch","of","[","`","treeprocessors","`","]","[","markdown.treeprocessors","]","are","run","against","the","[","`","ElementTree","`","]","[","xml.etree.ElementTree.ElementTree","]","object",".","One","such","`","treeprocessor","`","(","[","`","markdown.treeprocessors.InlineProcessor","`","]","[","]",")","runs","[","`","inlinepatterns","`","]","[","markdown.inlinepatterns","]","against","the","[","`","ElementTree","`","]","[","xml.etree.ElementTree.ElementTree","]","object",",","parsing","inline","markup",".","4",".","Some","[","`","postprocessors","`","]","[","markdown.postprocessors","]","are","run","against","the","text","after","the","[","`","ElementTree","`","]","[","xml.etree.ElementTree.ElementTree","]","object","has","been","serialized","into","text",".","5",".","The","output","is","returned","as","a","string","."]
code: def convert(self, source: str) -> str:
      """
      Convert a Markdown string to a string in the specified output format.
  
      Arguments:
          source: Markdown formatted text as Unicode or ASCII string.
  
      Returns:
          A string in the specified output format.
  
      Markdown parsing takes place in five steps:
  
      1. A bunch of [`preprocessors`][markdown.preprocessors] munge the input text.
      2. A [`BlockParser`][markdown.blockparser.BlockParser] parses the high-level structural elements of the
         pre-processed text into an [`ElementTree`][xml.etree.ElementTree.ElementTree] object.
      3. A bunch of [`treeprocessors`][markdown.treeprocessors] are run against the
         [`ElementTree`][xml.etree.ElementTree.ElementTree] object. One such `treeprocessor`
         ([`markdown.treeprocessors.InlineProcessor`][]) runs [`inlinepatterns`][markdown.inlinepatterns]
         against the [`ElementTree`][xml.etree.ElementTree.ElementTree] object, parsing inline markup.
      4. Some [`postprocessors`][markdown.postprocessors] are run against the text after the
         [`ElementTree`][xml.etree.ElementTree.ElementTree] object has been serialized into text.
      5. The output is returned as a string.
  
      """
  
      # Fix up the source text
      if not source.strip():
          return ""  # a blank Unicode string
  
      try:
          source = str(source)
      except UnicodeDecodeError as e:  # pragma: no cover
          # Customize error message while maintaining original traceback
          e.reason += ". -- Note: Markdown only accepts Unicode input!"
          raise
  
      # Split into lines and run the line preprocessors.
      self.lines = source.split("\n")
      for prep in self.preprocessors:
          self.lines = prep.run(self.lines)
  
      # Parse the high-level elements.
      root = self.parser.parseDocument(self.lines).getroot()
  
      # Run the tree-processors
      for treeprocessor in self.treeprocessors:
          newRoot = treeprocessor.run(root)
          if newRoot is not None:
              root = newRoot
  
      # Serialize _properly_.  Strip top-level tags.
      output = self.serializer(root)
      if self.stripTopLevelTags:
          try:
              start = (
                  output.index("<%s>" % self.doc_tag)
                  + len(self.doc_tag)
                  + 2
              )
              end = output.rindex("</%s>" % self.doc_tag)
              output = output[start:end].strip()
          except ValueError as e:  # pragma: no cover
              if output.strip().endswith("<%s />" % self.doc_tag):
                  # We have an empty document
                  output = ""
              else:
                  # We have a serious problem
                  raise ValueError(
                      "Markdown failed to strip top-level "
                      "tags. Document=%r" % output.strip()
                  ) from e
  
      # Run the text post-processors
      for pp in self.postprocessors:
          output = pp.run(output)
  
      return output.strip()
  
imports: from __future__ import annotations
  import codecs
  import sys
  import logging
  import importlib
  from typing import TYPE_CHECKING, Any, BinaryIO, Callable, ClassVar, Mapping, Sequence
  from .None import util
  from .preprocessors import build_preprocessors
  from .blockprocessors import build_block_parser
  from .treeprocessors import build_treeprocessors
  from .inlinepatterns import build_inlinepatterns
  from .postprocessors import build_postprocessors
  from .extensions import Extension
  from .serializers import to_html_string, to_xhtml_string
  from .util import BLOCK_LEVEL_ELEMENTS
label_desc: Use image node_id 9 for calling the Markdown obj's underlying member method code with example usage: obj.convert(source) and returns: output, str