Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Markdown compat #3604

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion requirements/requirements-optionals.txt
Original file line number Diff line number Diff line change
@@ -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.0
django-filter==0.10.0
17 changes: 13 additions & 4 deletions rest_framework/compat.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,16 +152,25 @@ def __init__(self, *args, **kwargs):
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 <h2>.
"""

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
Expand Down