  
  # Markdown is optional
  try:
      import markdown
      
      def apply_markdown(text):
          """
          Simple wrapper around :func:`markdown.markdown` to set the base level
          of '#' style headers to <h2>.
          """
 
</s> remove # If markdown is installed we also test it's working (and that our wrapped forces '=' to h2 and '-' to h3)
MARKED_DOWN = """<h2 id="an-example-docstring">an example docstring</h2>
 </s> add # If markdown is installed we also test it's working 
# (and that our wrapped forces '=' to h2 and '-' to h3)

# We support markdown < 2.1 and markdown >= 2.1
MARKED_DOWN_lt_21 = """<h2>an example docstring</h2>
<ul>
<li>list</li>
<li>list</li>
</ul>
<h3>another header</h3>
<pre><code>code block
</code></pre>
<p>indented</p>
<h2 id="hash_style_header">hash style header</h2>"""

MARKED_DOWN_gte_21 = """<h2 id="an-example-docstring">an example docstring</h2> </s> remove             self.assertEquals(apply_markdown(DESCRIPTION), MARKED_DOWN)
 </s> add             gte_21_match = apply_markdown(DESCRIPTION) == MARKED_DOWN_gte_21
            lt_21_match = apply_markdown(DESCRIPTION) == MARKED_DOWN_lt_21
            self.assertTrue(gte_21_match or lt_21_match) </s> remove         md = markdown.Markdown(extensions=extensions, safe_mode=safe_mode)
 </s> add         if markdown.version < (2, 1):
            output_format = markdown.DEFAULT_OUTPUT_FORMAT

            md = markdown.Markdown(extensions=markdown.load_extensions(extensions),
                               safe_mode=safe_mode,
                               output_format=output_format)
            md.parser.blockprocessors['setextheader'] = CustomSetextHeaderProcessor(md.parser)
        else:
            md = markdown.Markdown(extensions=extensions, safe_mode=safe_mode)
     
    class CustomSetextHeaderProcessor(markdown.blockprocessors.BlockProcessor):
        """
        Class for markdown < 2.1

        Override `markdown`'s :class:`SetextHeaderProcessor`, so that ==== headers are <h2> and ---- heade

        We use <h1> for the resource name.
        """
        import re
        # Detect Setext-style header. Must be first 2 lines of block.
        RE = re.compile(r'^.*?\n[=-]{3,}', re.MULTILINE)

        def test(self, parent, block):
            return bool(self.RE.match(block))

        def run(self, parent, blocks):
            lines = blocks.pop(0).split('\n')
            # Determine level. ``=`` is 1 and ``-`` is 2.
            if lines[1].startswith('='):
                level = 2
            else:
                level = 3
            h = markdown.etree.SubElement(parent, 'h%d' % level)
            h.text = lines[0].strip()
            if len(lines) > 2:
                # Block contains additional lines. Add to  master blocks for later.
                blocks.insert(0, '\n'.join(lines[2:]))

  
  # Markdown is optional
  try:
      import markdown
     
    class CustomSetextHeaderProcessor(markdown.blockprocessors.BlockProcessor):
        """
        Class for markdown < 2.1

        Override `markdown`'s :class:`SetextHeaderProcessor`, so that ==== headers are <h2> and ---- heade

        We use <h1> for the resource name.
        """
        import re
        # Detect Setext-style header. Must be first 2 lines of block.
        RE = re.compile(r'^.*?\n[=-]{3,}', re.MULTILINE)

        def test(self, parent, block):
            return bool(self.RE.match(block))

        def run(self, parent, blocks):
            lines = blocks.pop(0).split('\n')
            # Determine level. ``=`` is 1 and ``-`` is 2.
            if lines[1].startswith('='):
                level = 2
            else:
                level = 3
            h = markdown.etree.SubElement(parent, 'h%d' % level)
            h.text = lines[0].strip()
            if len(lines) > 2:
                # Block contains additional lines. Add to  master blocks for later.
                blocks.insert(0, '\n'.join(lines[2:]))

      def apply_markdown(text):
          """
          Simple wrapper around :func:`markdown.markdown` to set the base level
          of '#' style headers to <h2>.
          """
keep keep keep keep replace keep keep keep keep keep
 Fixes #94

Modified alazaro's commit sot that both markdown < 2.1 and >= 2.1 are
supported

The test checks if either matches the old or the new style. 
djangorestframework/compat.py