diff --git a/requirements/requirements-optionals.txt b/requirements/requirements-optionals.txt index bd488f052..42f1205af 100644 --- a/requirements/requirements-optionals.txt +++ b/requirements/requirements-optionals.txt @@ -1,4 +1,4 @@ # Optional packages which may be used with REST framework. -markdown==2.5.2 +markdown==2.6.4 django-guardian==1.3.2 django-filter==0.10.0 diff --git a/rest_framework/compat.py b/rest_framework/compat.py index de8e77ae7..054d6976e 100644 --- a/rest_framework/compat.py +++ b/rest_framework/compat.py @@ -153,16 +153,25 @@ if 'patch' not in View.http_method_names: try: import markdown + if markdown.version <= '2.2': + HEADERID_EXT_PATH = 'headerid' + else: + HEADERID_EXT_PATH = 'markdown.extensions.headerid' def apply_markdown(text): """ Simple wrapper around :func:`markdown.markdown` to set the base level of '#' style headers to

. """ - - extensions = ['headerid(level=2)'] - safe_mode = False - md = markdown.Markdown(extensions=extensions, safe_mode=safe_mode) + extensions = [HEADERID_EXT_PATH] + extension_configs = { + HEADERID_EXT_PATH: { + 'level': '2' + } + } + md = markdown.Markdown( + extensions=extensions, extension_configs=extension_configs + ) return md.convert(text) except ImportError: apply_markdown = None