mirror of
https://github.com/encode/django-rest-framework.git
synced 2024-11-23 10:03:57 +03:00
Merge pull request #3842 from linovia/markdown-compat
Markdown compat (overtakes #3604)
This commit is contained in:
commit
c2e94709a0
|
@ -1,4 +1,4 @@
|
||||||
# Optional packages which may be used with REST framework.
|
# Optional packages which may be used with REST framework.
|
||||||
markdown==2.5.2
|
markdown==2.6.4
|
||||||
django-guardian==1.3.2
|
django-guardian==1.3.2
|
||||||
django-filter==0.10.0
|
django-filter==0.10.0
|
||||||
|
|
|
@ -153,16 +153,25 @@ if 'patch' not in View.http_method_names:
|
||||||
try:
|
try:
|
||||||
import markdown
|
import markdown
|
||||||
|
|
||||||
|
if markdown.version <= '2.2':
|
||||||
|
HEADERID_EXT_PATH = 'headerid'
|
||||||
|
else:
|
||||||
|
HEADERID_EXT_PATH = 'markdown.extensions.headerid'
|
||||||
|
|
||||||
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
|
||||||
of '#' style headers to <h2>.
|
of '#' style headers to <h2>.
|
||||||
"""
|
"""
|
||||||
|
extensions = [HEADERID_EXT_PATH]
|
||||||
extensions = ['headerid(level=2)']
|
extension_configs = {
|
||||||
safe_mode = False
|
HEADERID_EXT_PATH: {
|
||||||
md = markdown.Markdown(extensions=extensions, safe_mode=safe_mode)
|
'level': '2'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
md = markdown.Markdown(
|
||||||
|
extensions=extensions, extension_configs=extension_configs
|
||||||
|
)
|
||||||
return md.convert(text)
|
return md.convert(text)
|
||||||
except ImportError:
|
except ImportError:
|
||||||
apply_markdown = None
|
apply_markdown = None
|
||||||
|
|
Loading…
Reference in New Issue
Block a user