mirror of
https://github.com/encode/django-rest-framework.git
synced 2025-02-25 16:00:49 +03:00
Remove support for markdown<2.1
This commit is contained in:
parent
6af75d3a69
commit
29dfbabaf5
|
@ -371,34 +371,6 @@ else:
|
||||||
try:
|
try:
|
||||||
import markdown
|
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):
|
def apply_markdown(text):
|
||||||
"""
|
"""
|
||||||
Simple wrapper around :func:`markdown.markdown` to set the base level
|
Simple wrapper around :func:`markdown.markdown` to set the base level
|
||||||
|
@ -407,21 +379,13 @@ try:
|
||||||
|
|
||||||
extensions = ['headerid(level=2)']
|
extensions = ['headerid(level=2)']
|
||||||
safe_mode = False,
|
safe_mode = False,
|
||||||
|
md = markdown.Markdown(extensions=extensions, safe_mode=safe_mode)
|
||||||
if markdown.version_info < (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)
|
|
||||||
return md.convert(text)
|
return md.convert(text)
|
||||||
|
|
||||||
except ImportError:
|
except ImportError:
|
||||||
apply_markdown = None
|
apply_markdown = None
|
||||||
|
|
||||||
|
|
||||||
# Yaml is optional
|
# Yaml is optional
|
||||||
try:
|
try:
|
||||||
import yaml
|
import yaml
|
||||||
|
|
Loading…
Reference in New Issue
Block a user