class_docstr: A class that represent a notebook cell as text
class_docstr_tok: ["A","class","that","represent","a","notebook","cell","as","text"]
docstr: Escape the given source, for a markdown cell
code: def markdown_to_text(self, source):
      """Escape the given source, for a markdown cell"""
      cell_markers = self.unfiltered_metadata.get(
          "cell_marker", self.fmt.get("cell_markers")
      )
      if cell_markers:
          if "," in cell_markers:
              left, right = cell_markers.split(",", 1)
          else:
              left = cell_markers + "\n"
              if cell_markers.startswith(("r", "R")):
                  cell_markers = cell_markers[1:]
              right = "\n" + cell_markers
  
          if (
              left[:3] == right[-3:]
              or (left[:1] in ["r", "R"] and left[1:4] == right[-3:])
          ) and right[-3:] in ['"""', "'''"]:
              # Markdown cells that contain a backslash should be encoded as raw strings
              if (
                  left[:1] not in ["r", "R"]
                  and "\\" in "\n".join(source)
                  and self.fmt.get("format_name") == "percent"
              ):
                  left = "r" + left
  
              source = copy(source)
              source[0] = left + source[0]
              source[-1] = source[-1] + right
              return source
  
      if (
          self.comment
          and self.comment != "#'"
          and is_active(self.ext, self.metadata)
          and self.fmt.get("format_name") not in ["percent", "hydrogen"]
      ):
          source = copy(source)
          comment_magic(
              source,
              self.language,
              self.comment_magics,
              explicitly_code=self.cell_type == "code",
          )
  
      return comment_lines(source, self.comment, self.comment_suffix)
  
imports: import re
  import warnings
  from copy import copy
  from .cell_metadata import _IGNORE_CELL_METADATA, is_active, metadata_to_double_percent_options, metadata_to_rmd_options, metadata_to_text
  from .cell_reader import LightScriptCellReader, MarkdownCellReader, RMarkdownCellReader
  from .doxygen import markdown_to_doxygen
  from .languages import _SCRIPT_EXTENSIONS, cell_language, comment_lines, same_language
  from .magics import comment_magic, escape_code_start, need_explicit_marker
  from .metadata_filter import filter_metadata
  from .pep8 import pep8_lines_between_cells
label_desc: Use image node_id 5 for calling the BaseCellExporter obj's underlying member method code with example usage: obj.markdown_to_text(source) and returns: comment_lines, source