diff options
| author | Marko Tibold | 2011-12-15 23:05:30 +0100 |
|---|---|---|
| committer | Marko Tibold | 2011-12-15 23:05:30 +0100 |
| commit | 1c8b40fb5f4744bc0bfa4448075eeed193ab950c (patch) | |
| tree | 9d9350c54f523569b377bbef942ba919d0e75b37 /djangorestframework/compat.py | |
| parent | c1858a2a9ab86dae4d4172a6b38a18a662e2530b (diff) | |
| parent | 4a60575132b2221e9abca432bbef57611b629a97 (diff) | |
| download | django-rest-framework-1c8b40fb5f4744bc0bfa4448075eeed193ab950c.tar.bz2 | |
Merge branch 'master' of https://github.com/alazaro/django-rest-framework into alazaro-master
Diffstat (limited to 'djangorestframework/compat.py')
| -rw-r--r-- | djangorestframework/compat.py | 37 |
1 files changed, 3 insertions, 34 deletions
diff --git a/djangorestframework/compat.py b/djangorestframework/compat.py index cae8c7b7..b7eedf85 100644 --- a/djangorestframework/compat.py +++ b/djangorestframework/compat.py @@ -374,48 +374,17 @@ else: # Markdown is optional try: import markdown - import re - - class CustomSetextHeaderProcessor(markdown.blockprocessors.BlockProcessor): - """ - Override `markdown`'s :class:`SetextHeaderProcessor`, so that ==== headers are <h2> and ---- headers are <h3>. - - We use <h1> for the resource name. - """ - - # 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 apply our :class:`CustomSetextHeaderProcessor`, - and also set the base level of '#' style headers to <h2>. + Simple wrapper around :func:`markdown.markdown` to set the base level + of '#' style headers to <h2>. """ extensions = ['headerid(level=2)'] safe_mode = False, - 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) + md = markdown.Markdown(extensions=extensions, safe_mode=safe_mode) return md.convert(text) except ImportError: |
