From 2c4ad8c0e2f1279846b3c268c19fbf63e8ee565b Mon Sep 17 00:00:00 2001 From: Tom Christie Date: Tue, 7 Mar 2017 10:54:00 +0000 Subject: [PATCH] Ensure markdown is optional. Closes #4941 --- rest_framework/templatetags/rest_framework.py | 21 +++---------------- 1 file changed, 3 insertions(+), 18 deletions(-) diff --git a/rest_framework/templatetags/rest_framework.py b/rest_framework/templatetags/rest_framework.py index a31c3ca94..280b084e1 100644 --- a/rest_framework/templatetags/rest_framework.py +++ b/rest_framework/templatetags/rest_framework.py @@ -9,7 +9,6 @@ from django.utils import six from django.utils.encoding import force_text, iri_to_uri from django.utils.html import escape, format_html, smart_urlquote from django.utils.safestring import SafeData, mark_safe -from markdown.extensions.fenced_code import FencedBlockPreprocessor from rest_framework.compat import ( NoReverseMatch, markdown, reverse, template_render @@ -24,22 +23,6 @@ register = template.Library() class_re = re.compile(r'(?<=class=["\'])(.*)(?=["\'])') -class CustomFencedBlockPreprocessor(FencedBlockPreprocessor): - CODE_WRAP = '%s' - LANG_TAG = ' class="highlight %s"' - - -class FencedCodeExtension(markdown.Extension): - - def extendMarkdown(self, md, md_globals): - """ Add FencedBlockPreprocessor to the Markdown instance. """ - md.registerExtension(self) - - md.preprocessors.add('fenced_code_block', - CustomFencedBlockPreprocessor(md), - ">normalize_whitespace") - - @register.tag(name='code') def highlight_code(parser, token): code = token.split_contents()[-1] @@ -92,7 +75,9 @@ def form_for_link(link): @register.simple_tag def render_markdown(markdown_text): - return markdown.markdown(markdown_text, extensions=[FencedCodeExtension(), "tables"]) + if not markdown: + return markdown_text + return markdown.markdown(markdown_text) @register.simple_tag